BillPull BillPull - 7 months ago 8
Javascript Question

Bind a function to Twitter Bootstrap Modal Close

I am using the Twitter Bootstrap lib on a new project and I want for part of the page to refresh and retrieve the latest json data on modal close. I dont see this anywhere in the documentation can someone point it out to me or suggest a solution.

Two problems with using the documented methods

$('#my-modal').bind('hide', function () {
// do something ...
});


I attach a "hide" class to the modal already so it does not display on page load so that would load twice

even if I remove the hide class and set the element id to "display:none" and add "console.log("THE MODAL CLOSED");" to the function above when I hit close nothing happens.

Answer

Bootstrap 3

$('#myModal').on('hidden.bs.modal', function () {
    // do something…
})

http://getbootstrap.com/javascript/#modals -> Events

Bootstrap 2.3.2

$('#myModal').on('hidden', function () {
    // do something…
})

http://getbootstrap.com/2.3.2/javascript.html#modals -> Events

Comments