Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap 3 Modal: how to check if modal is open or closed using jquery/javascript

Can anyone please tell me how to check bootstrap 3.0 modal status, is it open or closed using jQuery or javascript. I used following code but it works when you have opened a modal for one time otherwise gives data undefined error.

if($('#addMemberModal').data('bs.modal').isShown == true){
console.log("Modal is open");
}
like image 430
Faisal Shahzad Avatar asked Jul 25 '14 06:07

Faisal Shahzad


People also ask

How check pop-up is open or not in jQuery?

You can do this: $(document). on('click', '. checkifpop', function(e) { //console.


2 Answers

You can also use straight jQuery like this:

$('#myModal').is(':visible');
like image 83
alexoviedo999 Avatar answered Oct 02 '22 08:10

alexoviedo999


you can refer to their page http://getbootstrap.com/javascript/#modals

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

show.bs.modal
This event fires immediately when the show instance method is called. If caused by a click, the clicked element is available as the relatedTarget property of the event.

shown.bs.modal
This event is fired when the modal has been made visible to the user (will wait for CSS transitions to complete). If caused by a click, the clicked element is available as the relatedTarget property of the event.

hide.bs.modal
This event is fired immediately when the hide instance method has been called.

hidden.bs.modal This event is fired when the modal has finished being hidden from the user (will wait for CSS transitions to complete). loaded.bs.modal This event is fired when the modal has loaded content using the remote option.

like image 27
Se0ng11 Avatar answered Oct 02 '22 10:10

Se0ng11