Bootstrap modal event not fired
In your view you need to add dom ready function and write your code in it like,
$(function(){ // let all dom elements are loaded
$('#mymodal').on('hide.bs.modal', function (e) {
alert('event fired')
});
});
Working Demo
While the accepted answer is correct, I had a slightly different scenario which I didn't find an answer to.
I'm creating my modal's dynamically, so they don't exist on the page load. I'm adding them to the DOM with a JQuery .append('body')
. Therefore
$('#mymodal').on('hide.bs.modal', function(e) {
doesn't work....I had to change my event listener to
$(document).on('hide.bs.modal', '#mymodal', function(e) {
to work. Hopefully this will help others in the same situation as me.