Can I check if Bootstrap Modal currently Shown / Hidden Programatically?

Like bool a = if("#myModal").shown(); ?

I need true/false


Solution 1:

alert($('#myModal').hasClass('in'));

It will return true if modal is open

Solution 2:

The best method is given in the docs

$('#myModal').on('shown.bs.modal', function () {
  // will only come inside after the modal is shown
});

for more info refer http://getbootstrap.com/javascript/#modals

Solution 3:

its an old question but anyway heres something i used incase someone was looking for the same thing

if (!$('#myModal').is(':visible')) {
    // if modal is not shown/visible then do something
}

Solution 4:

When modal hide? we check like this :

$('.yourmodal').on('hidden.bs.modal', function () {
    // do something here
})