Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get twitter bootstrap modal to close (after initial launch)

I'm very much a noob, so I think I'm overseeing something (probably obvious) with twitter bootstrap modal. What I am trying to do is get a modal to launch only on mobile. This works fine with adding the class .visible-phone on the modal div. So far so good. But then I want it to work, meaning you can close it with the X button. And I cannot get the button to work.

<div class="modal visible-phone" id="myModal">   <div class="modal-header">     <button class="close" data-dismiss="modal">×</button>     <h3>text introductory<br>want to navigate to...</h3>  </div>  <div class="modal-body">     <ul class="nav">       <li> ... list of links here </li>     </ul>    </div>   </div> 

In the bottom of the html I put jquery.js (first) and bootstrap.modal.js and bootstrap.transition.js. Actually all of the bootstrap js modules (not to miss an include). I'm not experienced with js..

Please forgive me if I posed a really stupid Q. I could not find the answer to this specific situation in the log.

like image 955
Monique De Haas Avatar asked May 08 '12 08:05

Monique De Haas


People also ask

How do you force close modals?

Answer: Use the modal('hide') Method.

How do I stop Bootstrap modal pop up?

There are few ways to close modal in Bootstrap: click on a backdrop, close icon, or close button. You can also use JavaScript hide method. Click the button to launch the modal. Then click on the backdrop, close icon or close button to close the modal.

How do I manually close a Bootstrap modal?

.modal('hide') Manually hides a modal. Returns to the caller before the modal has actually been hidden (i.e. before the hidden.


2 Answers

$('#myModal').modal('hide') should do it

like image 109
ayal gelles Avatar answered Sep 26 '22 22:09

ayal gelles


I had problems closing the bootstrap modal dialog, if it was opened with:

$('#myModal').modal('show'); 

I solved this problem opening the dialog by the following link:

<a href="#myModal" data-toggle="modal">Open my dialog</a> 

Do not forget the initialization:

$('#myModal').modal({show: false}); 

I also used the following attributes for the closing button:

data-dismiss="modal" data-target="#myModal" 
like image 26
artkoenig Avatar answered Sep 25 '22 22:09

artkoenig