I'm having trouble using a bootstrap modal popup. Calling a popup is no issue, but trying to close it yields strange results. Instead of just hiding the popup and removing the backdrop, the popup gets hidden but another backdrop gets added, turning the screen almost black. the original backdrop does not get removed.
Below is the html code I've tried to use
<div id="popupDelete" class="modal hide fade" role="dialog">
<div class="modal-header">delete transaction line?</div>
<div class="moda-body">
<button id="deleteYes">yes</button>
<button class="cancelButton" data-dismiss="modal">no</button>
</div>
</div>
this is what I got from the bootstrap 2.3 docs and should work out of teh bix, like everything else from bootstrap.
I've also tried using javascript with the $('#popupDelete').modal('hide');
function, which had the same effect.
I'm having trouble using a bootstrap modal popup. Calling a popup is no issue, but trying to close it yields strange results. Instead of just hiding the popup and removing the backdrop, the popup gets hidden but another backdrop gets added, turning the screen almost black. the original backdrop does not get removed.
Below is the html code I've tried to use
<div id="popupDelete" class="modal hide fade" role="dialog">
<div class="modal-header">delete transaction line?</div>
<div class="moda-body">
<button id="deleteYes">yes</button>
<button class="cancelButton" data-dismiss="modal">no</button>
</div>
</div>
this is what I got from the bootstrap 2.3 docs and should work out of teh bix, like everything else from bootstrap.
I've also tried using javascript with the $('#popupDelete').modal('hide');
function, which had the same effect.
- 1 I just tried your code in my application and it works. Maybe some of your other JS interferes? – notan3xit Commented Aug 27, 2013 at 11:33
7 Answers
Reset to default 7This one worked for me
$('#popupDelete').modal('toggle');
I'm not sure if this is causing the problem, but there is a typo. It's
<div class="modal-body">
in line 3. There is missing an "l"
There was indeed javascript conficting with the closing of the popup. There was a line of javascript messing with all popups when clicking on a parent container, forcing them open again.
@dreagan, it may be happening like, when you click on open button for example, the popup is created dynamically, So you may be required the close Try this :
$('#popupDelete').close()
OR
$.modal.close();
Refer this How do you close a jQuery Simplemodal?
Whenever possible, place your modal HTML in a top-level position to avoid potential interference from other elements. You’ll likely run into issues when nesting a .modal
within another fixed element.
Way to create a modal dynamically (Bootstrap 5):
Html:
...
<button type="button" class="close" data-dismiss="modal" aria-label="Close" onclick="close_modal();">
<span aria-hidden="true">×</span>
</button>
...
Javascript:
var my_modal = new bootstrap.Modal(document.getElementById('my_modal'), {
keyboard: false
})
// To open
function open_modal () {
my_modal.open();
}
// To close
function close_modal ()
{
my_modal.hide();
}
Check you have added the scripts as well. and try toggle method to hide the modal.