Do something with jquery after clicking a link to close a modal

117 Views Asked by At

I have a modal with the following code to close it

a#modalclick.icon.icon-close.pull-left href="#mymodal"

I want to know when the x icon is clicked and the modal closed so I can do something with the link id.

My javascript is;

$('#modalclick').on('click', function(event) {
  console.log('clicked')
});

but it's not recognising the modal being clicked closed...

2

There are 2 best solutions below

0
On

Have you tried using .not(':visible') ?

if ( $('#yourdiv').not(':visible') ) {
  console.log('not visible');
}
2
On

use these events hidden.bs.modal, hide.bs.modal Docs.

JS

$('#mymodal').on('hidden.bs.modal', function(event) {
console.log('modal is being to be closed')
});
$('#mymodal').on('hide.bs.modal', function(event) {
console.log('modal hidden')
});