Can I check if Bootstrap Modal currently Shown / Hidden Programatically?
Like bool a = if(\"#myModal\").shown();
?
I need true/false
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
alert($('#myModal').hasClass('in'));
It will return true if modal is open
With Bootstrap 4:
if ($('#myModal').hasClass('show')) {
alert("Modal is visible")
}
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
}
if($('.modal').hasClass('in')) {
alert($('.modal .in').attr('id')); //ID of the opened modal
} else {
alert("No pop-up opened");
}