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.
if you want to fire a function on every modal close, you can use this method, $(document). ready(function (){ $('. modal').
Answer: Use the modal('hide') Method You can simply use the modal('hide') method to hide or close the modal window in Bootstrap using jQuery. Other related Bootstrap's modal methods are modal('show') and modal('toggle') .
When the Button is clicked, the HTML DIV is referenced using jQuery and its modal function is called along with properties data-backdrop: "static" and data-keyboard: false which disables the closing of the Bootstrap Modal Popup when clicked outside.
$('#myModal').on('hidden.bs.modal', function () { // do something… });
Bootstrap 3: getbootstrap.com/javascript/#modals-events
Bootstrap 4: getbootstrap.com/docs/4.1/components/modal/#events
$('#myModal').on('hidden', function () { // do something… });
See getbootstrap.com/2.3.2/javascript.html#modals → Events
$('#my-modal').on('hidden.bs.modal', function () { window.alert('hidden event fired!'); });
See this JSFiddle for a working example:
https://jsfiddle.net/6n7bg2c9/
See the Modal Events section of the docs here:
https://getbootstrap.com/docs/4.3/components/modal/#events
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With