Put modal('toggle') instead of modal(toggle)
$(function () {
$('#modal').modal('toggle');
});
Answer from Tamil Selvan C on Stack OverflowBootstrap
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.
Top answer 1 of 16
868
Put modal('toggle') instead of modal(toggle)
$(function () {
$('#modal').modal('toggle');
});
2 of 16
514
to close bootstrap modal you can pass 'hide' as option to modal method as follow
$('#modal').modal('hide');
Please take a look at working fiddle here
bootstrap also provide events that you can hook into modal functionality, like if you want to fire a event when the modal has finished being hidden from the user you can use hidden.bs.modal event you can read more about modal methods and events here in Documentation
If none of the above method work, give a id to your close button and trigger click on close button.
Videos
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.
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">×</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.
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
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();
Laracasts
laracasts.com › discuss › channels › general-discussion › how-to-hide-a-bootstrap-5-modal-window-in-pure-javascript
How to hide a Bootstrap 5 modal window in pure JavaScript ?
We cannot provide a description for this page right now
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
Jquery
forum.jquery.com › portal › en › community › topic › how-to-trigger-an-event-when-bootstrap-modal-closes
How to trigger an event when bootstrap modal closes
We cannot provide a description for this page right now
Bootstrap
getbootstrap.com › docs › 5.3 › components › close-button
Close button · Bootstrap v5.3
A generic close button for dismissing content like modals and alerts.
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.