If after modal hide, faded background is remained and does not let you click any where you can forcefully remove those by using below piece of code.

First hide (all) your modal div elements.

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

Secondly remove 'modal-open' class from body and '.modal-backdrop' at the end of the page.

$('body').removeClass('modal-open');
$('.modal-backdrop').remove();
Answer from Gampesh on Stack Overflow
🌐
GitHub
github.com › valor-software › ngx-bootstrap › issues › 853
Backdrop not being removed after hiding Modal · Issue #853 · valor-software/ngx-bootstrap
June 28, 2016 - I have a custom component that shows a Modal after clicking a button. Within the Modal body, the user user is presented a anchor link that routes the user away from the current view. When the user does so, the Modal is hidden/destroyed but the Backdrop is not.
Author   JayCallas
🌐
Bootstrap
getbootstrap.com › docs › 4.4 › components › modal
Modal · Bootstrap
The modal plugin toggles your hidden content on demand, via data attributes or JavaScript. It also adds .modal-open to the <body> to override default scrolling behavior and generates a .modal-backdrop to provide a click area for dismissing shown modals when clicking outside the modal.
Top answer
1 of 16
596

Make sure you're not replacing the container containing the actual modal window when you're doing the AJAX request, because Bootstrap will not be able to find a reference to it when you try to close it. In your Ajax complete handler remove the modal and then replace the data.

If that doesn't work you can always force it to go away by doing the following:

$('#your-modal-id').modal('hide');
$('body').removeClass('modal-open');
$('.modal-backdrop').remove();
2 of 16
67

Make sure that your initial call to $.modal() to apply the modal behavior is not passing in more elements than you intended. If this happens, it will end up creating a modal instance, complete with backdrop element, for EACH element in the collection. Consequently, it might look like the backdrop has been left behind, when actually you're looking at one of the duplicates.

In my case, I was attempting to create the modal content on-the-fly with some code like this:

myModal = $('<div class="modal">...lots of HTML content here...</div><!-- end modal -->');
$('body').append(myModal);
myModal.modal();

Here, the HTML comment after the closing </div> tag meant that myModal was actually a jQuery collection of two elements - the div, and the comment. Both of them were dutifully turned into modals, each with its own backdrop element. Of course, the modal made out of the comment was invisible apart from the backdrop, so when I closed the real modal (the div) it looked like the background was left behind.

🌐
GitHub
github.com › twbs › bootstrap › issues › 16320
Modal backdrop does not disappear, when modal-dialog being removed in HTML · Issue #16320 · twbs/bootstrap
January 15, 2015 - Expected behavior: the backdrop will be removed automatically, when the modal wrapper disappears.
Author   SilverFire
🌐
Drupal
drupal.org › project › bootstrap › issues › 3018531
Modal-backdrop doesn't disappear [#3018531] | Drupal.org
September 13, 2024 - We are experiencing this issue, and I do think it is an issue with the Bootstrap theme. Feel free to close the issue again if you feel this isn't related. In our case we are having issues with a modal generated by the autologout module. When the modal is closed autologout.js calls jquery modal's destroy function $(this).dialog("destroy") (Dialog destroy documentation) This closes the modal, but leaves the backdrop visible.
🌐
MDBootstrap
mdbootstrap.com › standard › material design for bootstrap 5 & vanilla javascript
Modal backdrop: static not allowing clicks without closing t - Material Design for Bootstrap
The tittle says it all. Regarding documentation https://mdbootstrap.com/angular/advanced/modals/#options Type: boolean | "static" Includes a modal-backdrop element. Alternatively, specify static for a backdrop which doesn't close the modal on click.
🌐
Bootstrap
getbootstrap.com › docs › 5.0 › components › modal
Modal · Bootstrap v5.0
I will not close if you click outside me. Don't even try to press escape key. ... <!-- Button trigger modal --> <button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#staticBackdrop"> Launch static backdrop modal </button> <!-- Modal --> <div class="modal fade" id="staticBackdrop" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title" id="staticBackdropLabel">Modal title</h5> <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> </div> <div class="modal-body"> ...
🌐
ASPSnippets
aspsnippets.com › questions › 131531 › Solved-Bootstrap-Modal-backdrop-does-not-disappear-after-modal-close-in-ASPNet-MVC
Solved Bootstrap Modal backdrop does not disappear after modal close in ASPNet MVC
October 19, 2020 - @{ Layout = null; } <!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width" /> <title>Index</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.4.0/css/bootstrap.min.css" /> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.4.0/js/bootstrap.min.js"></script> <script> $(function () { $('#myModal2').on('show.bs.modal', function (e) { $('#myModal2').focus(); }) }); </script
Find elsewhere
🌐
Tutorial Republic
tutorialrepublic.com › faq › how-to-prevent-bootstrap-modal-from-closing-when-clicking-outside.php
How to Prevent Bootstrap Modal from Closing when Clicking Outside
But you can prevent this from happening by setting the modal's backdrop option to static and keyboard option to false, as shown in the following example: ... <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Disallow Bootstrap ...
🌐
Bootstrap
getbootstrap.com › docs › 5.3 › components › modal
Modal · Bootstrap v5.3
Use Bootstrap’s JavaScript modal ... user notifications, or completely custom content. ... Before getting started with Bootstrap’s modal component, be sure to read the following as our menu options have recently changed. Modals are built with HTML, CSS, and JavaScript. They’re positioned over everything else in the document and remove scroll from the <body> so that modal content scrolls instead. Clicking on the modal “backdrop” will automatically close the ...
🌐
Rick Strahl's Web Log
weblog.west-wind.com › posts › 2016 › sep › 14 › bootstrap-modal-dialog-showing-under-modal-background
Bootstrap Modal Dialog showing under Modal Background - Rick Strahl's Web Log
I've experimented with a lot of different things and the only things that work reliably are not using a background and delay updating the z-order (out of band). ... I ran into the same problem using bootstrp-dialog and this worked for me. Has the added bonus that the dialog doesn't close if you accidently click on the background. ... I solved it like you said and to simulate that backdrop I simply add background to modal in rgba format
🌐
GitHub
github.com › twbs › bootstrap › issues › 12990
$(...).modal('hide') not clearing the modal backdrop · Issue #12990 · twbs/bootstrap
March 9, 2014 - I am using Backbone Marionette region for Bootstrap Modal in an app I am developing, in which I need to have the modal close after a succesfull server sync. For some reason, ´´´ this.$el.modal("hide")´´´ does not clear the backdrop created by the modal, but when clicking the "close" button it clears everything.
Author   rodryquintero
🌐
Stack Overflow
stackoverflow.com › questions › 54544024
css - Modal backdrop is not going away after calling .hide() - ...
The element to which you want to apply the hide function is <modal-wrapper>. When you hide that, the <modal-backdrop> will also be hidden. You are probably hiding <modal-container> instead, and so <modal-backdrop> is still displayed.
🌐
MDBootstrap
mdbootstrap.com › standard › material design for bootstrap 5 & vanilla javascript
Modal Backdrop stuck - Material Design for Bootstrap
<div mdbModal #newStorePopup="mdb-modal" class="modal fade" id="centralModalSuccess" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" [config]="{keyboard: false}" style="overflow: auto"> <div class="modal-dialog modal-notify" role="document"> <div class="modal-content"> </div> </div> </div> and after calling newStorePopup.hide() to close the pop up. Error below will happens and the overlay will be stuck. :( ERROR TypeError: Cannot read property 'backdrop' of undefined at ModalDirective.push../node_modules/ng-uikit-pro-standard/fesm5/ng-uikit-pro-standard.js.ModalDi
🌐
GitHub
github.com › twbs › bootstrap › issues › 33727
Can't close a Modal using JS · Issue #33727 · twbs/bootstrap
April 23, 2021 - jsp3Medium priority, and does not prevent the core functionalityMedium priority, and does not prevent the core functionalityv5 ... I could remove the backdrop myself document.querySelector('.modal-backdrop')?.remove() but that feels quite hacky, this internal part should be part of bootstrap API
Author   caub
🌐
MDBootstrap
mdbootstrap.com › standard › modal backdrop
Bootstrap Modal Backdrop - free examples & tutorial
Backdrop options for a responsive popup with Bootstrap 5. Prevent close on click outside with static backdrop, remove backdrop, enable interactivity & more. Default modal backdrop is a delicate shadow overlaying the rest of the page design.
🌐
MDBootstrap
mdbootstrap.com › standard › material design for bootstrap 5 & vanilla javascript
Don&#039;t dismiss modal on backdrop click - Material Design for Bootstrap
I have created a snippet with modal which is not closed on outside click: https://mdbootstrap.com/snippets/jquery/m-dembna/1199872 . Simply add data-backdrop="false" to your div with modal class.
🌐
MDBootstrap
mdbootstrap.com › standard › material design for bootstrap 5 & vanilla javascript
Modal backdrop is not working - Material Design for Bootstrap
import React, { Component } from 'react'; import { MDBContainer, MDBBtn, MDBModal, MDBModalBody, MDBModalHeader, MDBModalFooter } from 'mdbreact'; import './App.css'; //Import here your styles if you need class ModalPage extends Component { state = { modal: false }; toggle = () => { this.setState({ modal: !this.state.modal }); }; render() { return ( <MDBContainer> <MDBBtn onClick={this.toggle}>Modal</MDBBtn> <MDBModal isOpen={this.state.modal} toggle={this.toggle} backdrop={false} wrapClassName={'backdropFix'} > <MDBModalHeader toggle={this.toggle}>MDBModal title</MDBModalHeader> <MDBModalBody>(...)</MDBModalBody> <MDBModalFooter> <MDBBtn color='secondary' onClick={this.toggle}> Close </MDBBtn> <MDBBtn color='primary'>Save changes</MDBBtn> </MDBModalFooter> </MDBModal> </MDBContainer> ); } } export default ModalPage;