Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Close Bootstrap Modal

I have a bootstrap modal dialog box that I want to show initially, then when the user clicks on the page, it disappears. I have the following:

$(function () {    $('#modal').modal(toggle) });   <div class="modal" id='modal'>      <div class="modal-header">         <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>         <h3 id="myModalLabel">Error:</h3>         </div>         <div class="modal-body">         <p>Please correct the following errors:</p>         </div>      </div>  </div> 

The modal is displayed initially, but it does not close when clicked outside of the modal. Also, the content area is not greyed out.. How can I get the modal to display initially, then close after the user clicks outside the area? And how can I get the background to be grayed out as in the demo?

like image 889
Nick B Avatar asked May 11 '13 02:05

Nick B


People also ask

How do I manually close a Bootstrap modal?

Answer: Use the modal('hide') Method 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 you close a modal in HTML?

To close a modal, add the w3-button class to an element together with an onclick attribute that points to the id of the modal (id01). You can also close it by clicking outside of the modal (see example below). Tip: &times; is the preferred HTML entity for close icons, rather than the letter "x".

How do you close a modal component?

To close the modal, simply call the handleClose() function inside the onLoginFormSubmit() function body.


1 Answers

Put modal('toggle') instead of modal(toggle)

$(function () {    $('#modal').modal('toggle'); }); 
like image 137
Tamil Selvan C Avatar answered Sep 20 '22 23:09

Tamil Selvan C