Open Bootstrap modal from dynamicallly created button?

I'm building a table in PHP using...

echo '<td><button type="button" class="btn btn-default btn-xs" id="edit_'. $info['tablename'] .'">Edit</button></td>';

I have this #editModal modal in my html lifted straight from Bootstrap...

<div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="editModalLabel" aria-hidden="true">
    //Modal content from Bootstrap example.
</div>

When I click the "Edit" button, nothing happens. No console errors, nothing. The delet commands that I've left out work just fine but it doesn't involve modals. Here's the jQuery I'm trying to use...

$(document).on('click',".table .btn",function (e) {
    e.preventDefault();
    var array = String($(this).attr('id')).split('_');
    var id = array[1];
    //Get the command off the button id.
    var command = array[0];

    if (command == "delete" ){
        //do delete stuff
    }   
    if (command == "edit" ){
        // I want to show this modal but it doesn't work.
        $('#editModal').modal({
            "show":"true"   
        });
    }
});

Answers


I think you just need the following.

if (command == "edit" ){
    // I want to show this modal but it doesn't work.
    $('#editModal').modal("show");
}

Need Your Help

UIViewController do not call dealloc in ARC project?

iphone objective-c automatic-ref-counting

In an ARC project, I addObserver for a notification in viewDidLoad: and removeObserver: in dealloc. But after I pop the viewController, dealloc is not executed.

Is there a simulator/emulator of Xeon Phi?

c++ c parallel-processing intel-mic xeon-phi

I am going to offload some computation to Xeon Phi but would like to test different APIs and different apporached to the parallel programming first.