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?
Besides, you can "click" on a 'x', that closes dialog. E.g.:
$(".ui-dialog-titlebar-close").click();
some times the solution up doesn't work so you d have properly to remove the in class and add the css display:none manually .
this worked for me:
use this link modal close
or
should work.
But if nothing else works you can call the modal close button directly:
This works well
However, when you have multiple modals stacking on top one another it is not effective, so instead , this works
this one is pretty good and it also works in angular 2