Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide Bootstrap previous modal when you opening new one?

I have such trouble: I have authentification which is made using Bootstrap modals.

When user opens sign in modal he can go to sign up modal ( or other ) . So, I need to close previous one.

Now I'm closing them like this:

$(document).ready(function(){   $("a").click(function() {   $("#login").hide();   $("#sign_up").hide();  })   }); 

but when I'm doing this - I can't reopen sign in modal( after click on sign up from sign in) until I refresh the page.

Can someone suggest how to check on what modal I'm clicking on the link and close it, when call another one ? Is there any universal way to close previous modal ?

like image 734
MID Avatar asked Sep 21 '12 13:09

MID


People also ask

How do I show and hide modals in Bootstrap?

You can simply use the modal('hide') method to hide or close the modal window in Bootstrap using jQuery. Other related Bootstrap's modal methods are modal('show') and modal('toggle') .

How do I hide the modal when I click outside?

Another way to dismiss the modal when clicking outside involved taking advantage of the bubbling nature of the javascript events. clicking on . modal will cause the click event to propagate like this . modal -> #modal-root -> body while clicking outside the modal will only go through #modal-root -> body .


1 Answers

You hide Bootstrap modals with:

$('#modal').modal('hide'); 

Saying $().hide() makes the matched element invisible, but as far as the modal-related code is concerned, it's still there. See the Methods section in the Modals documentation.

like image 96
willglynn Avatar answered Sep 24 '22 07:09

willglynn