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

$(function () {
   $('#modal').modal('toggle');
});
Answer from Tamil Selvan C on Stack Overflow
🌐
Bootstrap
getbootstrap.com › docs › 4.0 › components › modal
Modal · Bootstrap
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 modal.
🌐
MDB
mdbootstrap.com › standard › how to close modal in bootstrap
How to close modal in Bootstrap - code helpers
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.
🌐
Bootstrap
getbootstrap.com › docs › 5.3 › components › modal
Modal · Bootstrap v5.3
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 modal.
🌐
W3Schools
w3schools.com › bootstrap › bootstrap_modal.asp
Bootstrap Modal Plugin
The .modal-header class is used to define the style for the header of the modal. The <button> inside the header has a data-dismiss="modal" attribute which closes the modal if you click on it.
🌐
Bootstrap
getbootstrap.com › docs › 5.0 › components › modal
Modal · Bootstrap v5.0
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 modal.
🌐
Tutorial Republic
tutorialrepublic.com › faq › how-to-close-a-bootstrap-modal-window-using-jquery.php
How to Close a Bootstrap Modal Window Using jQuery
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>jQuery Close Bootstrap Modal Window on Button Click</title> <link rel="stylesheet" href="css/bootstrap.min.css"> <script src="js/jquery-3.5.1.min.js"></script> <script src="js/bootstrap.min.js"></script> <script> $(document).ready(function(){ // Open modal on page load $("#myModal").modal('show'); // Close modal on button click $(".btn").click(function(){ $("#myModal").modal('hide'); }); }); </script> <style> .bs-example{ margin: 20px; } </style> </head> <body> <div class="bs-example"> <div id="myModal" class="modal fade" tabindex="-1"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title">Modal Title</h5> <button type="button" class="close" data-dismiss="modal">&times;</button> </div> <div class="modal-body"> <p>This is a simple Bootstrap modal.
🌐
Bootstrap
getbootstrap.com › docs › 5.0 › components › close-button
Close button · Bootstrap v5.0
There's a newer version of Bootstrap! ... A generic close button for dismissing content like modals and alerts.
Find elsewhere
🌐
GitHub
github.com › mdbootstrap › bootstrap-how-to-close-modal
GitHub - mdbootstrap/bootstrap-how-to-close-modal: Learn how to close modal in Bootstrap choosing one of a few ways: click on a backdrop, close icon, or close button. You can also use JavaScript hide method. · GitHub
Learn how to close modal in Bootstrap choosing one of a few ways: click on a backdrop, close icon, or close button. You can also use JavaScript hide method. - mdbootstrap/bootstrap-how-to-close-modal
Author   mdbootstrap
🌐
Bootstrap
getbootstrap.com › docs › 4.6 › components › modal
Modal · Bootstrap v4.6
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 modal.
🌐
Netcreator
netcreator.co.in › blog › bootstrap-modal-close-method-bootstrap-modalhide-method
Bootstrap modal close method Bootstrap .modal(“hide”) method – Netcreator
You need to use the .modal(‘hide’) method to close the modal popup. ... var modalElement = document.getElementById('myModal'); var modal = bootstrap.Modal.getInstance(modalElement); modal.hide();
🌐
MDBootstrap
mdbootstrap.com › standard › modal close event
Bootstrap Modal close event - free examples & tutorial
An example of a bootstrap modal close event. Easy to implement and customize. Examples of basic and advanced usage.
🌐
MDBootstrap
mdbootstrap.com › standard › modal show, close, hide & toggle
Bootstrap 5 Modal Show, Close, Hide & Toggle - free examples
Methods for responsive Popup with Bootstrap 5. Show, hide / close or toggle a modal with JavaScript or via data attributes.
🌐
GeeksforGeeks
geeksforgeeks.org › bootstrap › how-to-handle-the-modal-closing-event-in-twitter-bootstrap
How to handle the modal closing event in Twitter Bootstrap? - GeeksforGeeks
July 12, 2025 - </p> </div> <div class="modal-footer"> <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button> <!-- The close button in the bottom of the modal --> <button type="button" class="btn btn-primary"> okay </button> <!-- ...
🌐
W3Schools
w3schools.com › bootstrap › tryit.asp
Modal Events - hide.bs.modal
The W3Schools online code editor allows you to edit code and view the result in your browser
🌐
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
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Disallow Bootstrap Modal from Closing</title> <link rel="stylesheet" href="css/bootstrap.min.css"> <script src="js/jquery-3.5.1.min.js"></script> <script src="js/bootstrap.min.js"></script> <script> $(document).ready(function(){ $(".show-modal").click(function(){ $("#myModal").modal({ backdrop: 'static', keyboard: false }); }); }); </script> </head> <body> <!-- Button HTML (to Trigger Modal) --> <input type="button" class="btn btn-lg btn-primary show-modal" value="Show Demo Modal"> <!-- Modal HTML --> <div id="myModal" class
🌐
BootstrapVue
bootstrap-vue.org › docs › components › modal
Modal | Components | BootstrapVue
You can set the value of trigger by passing an argument to the component's hide() method for advanced control (i.e. detecting what button or action triggered the modal to hide). Note: ok, cancel, or close events will be only emitted when the argument to hide() is strictly 'ok', 'cancel', or 'headerclose' respectively. The argument passed to hide() will be placed into the trigger property of the event object. Utilize the Bootstrap grid system within a modal by nesting <b-container fluid> within the modal-body.