Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • JS Tutorial
  • JS Exercise
  • JS Interview Questions
  • JS Array
  • JS String
  • JS Object
  • JS Operator
  • JS Date
  • JS Error
  • JS Projects
  • JS Set
  • JS Map
  • JS RegExp
  • JS Math
  • JS Number
  • JS Boolean
  • JS Examples
  • JS Free JS Course
  • JS A to Z Guide
  • JS Formatter
Open In App
Next Article:
How to get the same behavior with confirm and bootstrap modal?
Next article icon

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">                               &times;                           </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:

modelOutput

Next Article
How to get the same behavior with confirm and bootstrap modal?

A

AnamikaP
Improve
Article Tags :
  • JavaScript
  • Web Technologies
  • Bootstrap
  • Bootstrap-4
  • Bootstrap-Misc

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
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences