- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Bootstrap .modal("toggle") method
Use the .modal(“toggle”) method in Bootstrap to toggle the modal.
As shown below, the modal generates on the click of a button −
$(document).ready(function(){ $("#button1").click(function(){ $("#newModal").modal("toggle"); }); });
Here is the button used above −
<button type="button" class="btn btn-default btn-lg" id="button1"> Modal One </button>
You can try to run the following code to implement the modal(“toggle”) method −
Example
<!DOCTYPE html> <html lang="en"> <head> <title>Bootstrap Example</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> </head> <body> <div class="container"> <h2>Sample</h2> <button type="button" class="btn btn-default btn-lg" id="button1">Modal One</button> <div class="modal fade" id="newModal" role="dialog"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal">×</button> <h4 class="modal-title">Sample Modal</h4> </div> <div class="modal-body"> <p>Click outside to close it.</p> </div> <div class="modal-footer"> <button type="button" class="btn btn-primary" data-dismiss="modal">Close</button> </div> </div> </div> </div> </div> <script> $(document).ready(function(){ $("#button1").click(function(){ $("#newModal").modal("toggle"); }); }); </script> </body> </html>
- Related Articles
- Toggle Bootstrap Modal
- Bootstrap .tooltip("toggle") method
- Bootstrap .modal("hide") method
- Bootstrap .modal("show") method
- modal(options) method in Bootstrap
- Implement .popover("toggle") method in Bootstrap
- Hide Bootstrap Modal
- Open Bootstrap Modal
- Style the Bootstrap modal
- Set small modal in Bootstrap
- Set large modal in Bootstrap
- Usage of Bootstrap Modal Plugins
- jQuery toggle() Method
- Header of the modal in Bootstrap
- Footer of the modal in Bootstrap

Advertisements