How to get the same behavior with confirm and bootstrap modal? Last Updated : 26 Jul, 2024 Comments Improve Suggest changes Like Article Like Report Bootstrap modal: In simple words, the Modal component is a dialog box/popup window that is displayed on top of the current page, once the trigger button is clicked. However, clicking on the modal’s backdrop automatically closes the modal. Also, it must be kept in mind that Bootstrap doesn’t support nested modals as they create bad UI experience for the user. Therefore, only one modal window is supported at a time. Example: html <html> <script src= "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"> </script> <script src= "https://cdn.jsdelivr.net/npm/[email protected]/dist/js/jquery.smartWizard.min.js"> </script> <script src= "https://cdnjs.cloudflare.com/ajax/libs/1000hz-bootstrap-validator/0.11.5/validator.min.js"> </script> <link rel="stylesheet" href= "https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"> <link rel="stylesheet" href= "https://cdn.jsdelivr.net/npm/[email protected]/dist/css/smart_wizard.min.css"> <script src= "https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity= "sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"> </script> <script src= "https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity= "sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"> </script> <body> <center> <h1 style="color:green">GeeksforGeeks</h1> <!-- Button trigger modal --> <button type="button" id="launchid" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal"> Launch demo modal </button> <!-- Modal --> <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true"> <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title" id="exampleModalLabel"> Modal title </h5> <button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true"> × </span> </button> </div> <div class="modal-body"> Woohoo, you're reading this text in a modal! </div> <div class="modal-footer"> <button type="button" id="closeid" class="btn btn-secondary" data-dismiss="modal"> Close </button> <button type="button" id="saveid" class="btn btn-primary"> Save changes </button> </div> </div> </div> </div> <div class="alert" role="alert" id="result"></div> </center> <script> var modalConfirm = function(callback) { $("#launchid").on("click", function() { $("exampleModal").modal('show'); }); $("#saveid").on("click", function() { callback(true); $("#exampleModal").modal('hide'); }); $("#closeid").on("click", function() { callback(false); $("#exampleModal").modal('hide'); }); }; modalConfirm(function(confirm) { if (confirm) { $("#result").html("Changes Saved"); } else { $("#result").html("Not Saved"); } }); </script> </body> </html> Output: Comment More infoAdvertise with us Next Article How to get the same behavior with confirm and bootstrap modal? A AnamikaP Follow Improve Article Tags : JavaScript Web Technologies Bootstrap Bootstrap-4 Bootstrap-Misc +1 More Similar Reads How to configure modal width in Bootstrap? Bootstrap Modal: It is a dialog window that opens inside the browser window on triggering certain events. It is a really convenient way to improve the website's content rendering as per the requirements. In this article, we will focus on adjusting the width/height of the modal box.Method 1: Using pr 2 min read How to Align Modal to Center of the Screen in Bootstrap? Aligning a modal to the center of the screen in Bootstrap means positioning the modal window vertically and horizontally at the center of the viewport. This can be achieved using Bootstrap's classes like modal-dialog-centered, which ensures the modal appears in the middle, providing a balanced and u 1 min read How to create a basic Modal component in Bootstrap ? Modals are JavaScript pop-ups that help us to deliver very useful content in the website like displaying save, delete, download or close confirmation on the website. Bootstrap modals are lightweight and multipurpose JavaScript components. They are also customizable and responsive components. In this 2 min read How to handle the modal closing event in Twitter Bootstrap? Modal Closing Event in Twitter Bootstrap | Set 1 Prerequisite Knowledge: Bootstrap 4 | Modal Twitter Bootstrapâs modal class offer a few events that are fired at the standard Bootstrap modal class. Bootstrap Modals offer a lightweight, multi-purpose JavaScript popup that is customizable and responsi 3 min read How to pass data to a React Bootstrap modal? In React Bootstrap, we have the styling and interactive components of Modal. In simple terms, Modal is nothing but the popup box that is opened when some action has been performed. To make the modal customizable in terms of its behavior, we can pass the custom data to the React Bootstrap modal using 4 min read Like