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.
Starting Bootstrap 3 (edit: still the same in Bootstrap 4) there are 2 instances in which you can fire up events, being:
1. When modal "hide" event starts
2. When modal "hide" event finished
Ref: http://getbootstrap.com/javascript/#js-events
Bootstrap provide events that you can hook into modal, like if you want to fire a event when the modal has finished being hidden from the user you can use hidden.bs.modal event like this
Check a working fiddle here read more about modal methods and events here in Documentation
In stead of "live" you need to use "on" event, but assign it to the document object:
Use:
Bootstrap 4:
hide.bs.modal: This event is fired immediately when the hide instance method has been called.
hidden.bs.modal: This event is fired when the modal has finished being hidden from the user (will wait for CSS transitions to complete).