0

I need to make a function call whenever my Bootstrap modal closes (hides). This means whenever someone clicks off the modal, if they press escape, or if they click the "x" close button.

Using $("#myModal").on("hidden.bs.modal", function (e) {}); does not capture when someone presses escape or clicks off the modal, it only captures the clicking of the close button.

How can I execute a function WHENEVER my modal closes and not just on trigger of the close button?

James
  • 445
  • 1
  • 6
  • 19
  • The hidden event fires no matter how the modal is closed. http://jsfiddle.net/1aeur58f/4859/ – Turnip Aug 10 '18 at 12:56

1 Answers1

0

Bootstrap 3 / 4

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

See Events Bootstrap 3

Bootstrap 2.3.2

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

See Events bootstrap 2.3.2

You can try listening to these events.


Would it be possible to know the version of Bootstrap that you use?

Reference Link

Pekee
  • 177
  • 1
  • 8
  • 1
    Thanks for the advice, in the end it was because elements were being dynamically added and I had to re-structure my jquery to actually get those new elements. – James Aug 10 '18 at 13:53