VOOZH about

URL: https://www.geeksforgeeks.org/bootstrap/bootstrap-5-modal-toggle-method/

⇱ Bootstrap 5 Modal toggle() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Bootstrap 5 Modal toggle() Method

Last Updated : 31 Jul, 2024

The Bootstrap 5 Modal toggle() method is used to directly toggle a modal i.e. show or hide. This method shows the result before the show or hide event occurs.

Syntax:

modal.toggle()

Return Value:

The user receives a direct response from this method before the modal is ever displayed or hidden.

Example 1: In this article, we used the toggle() method of the Bootstrap 5 Modal component to toggle its visibility. Here the modal's visibility is toggled when we click the button and after 3 seconds it toggles its visibility again.

Output:

Example 2: This is another example illustrating the use of the toggle() method of the Modal component with buttons.

Output:

Reference: https://getbootstrap.com/docs/5.0/components/modal/#toggle

Comment
Article Tags:

Explore