if you want to fire a function on every modal close, you can use this method, $(document). ready(function (){ $('. modal').
To trigger the modal window, you need to use a button or a link. Then include the two data-* attributes: data-toggle="modal" opens the modal window. data-target="#myModal" points to the id of the modal.
You can use the shown event/show event based on what you need:
$( "#code" ).on('shown', function(){
alert("I want this to appear after the modal has opened!");
});
Demo: Plunker
For Bootstrap 3.0 you can still use the shown event but you would use it like this:
$('#code').on('shown.bs.modal', function (e) {
// do something...
})
See the Bootstrap 3.0 docs here under "Events".
will not work.. use $(window)
instead
$(window).on('shown.bs.modal', function() {
$('#code').modal('show');
alert('shown');
});
$(window).on('hidden.bs.modal', function() {
$('#code').modal('hide');
alert('hidden');
});
you can use show
instead of shown
for making the function to load just before modal open, instead of after modal open.
$('#code').on('show.bs.modal', function (e) {
// do something...
})
Bootstrap modal exposes events. Listen for the the shown
event like this
$('#my-modal').on('shown', function(){
// code here
});
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