VOOZH about

URL: https://www.geeksforgeeks.org/bootstrap/bootstrap-5-collapse-methods/

⇱ Bootstrap 5 Collapse Methods - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Bootstrap 5 Collapse Methods

Last Updated : 27 Jul, 2025

Bootstrap 5 Collapse Methods are used to control the visibility of a Bootstrap 5 Collapse element, manually.

Bootstrap 5 Collapse Methods:

  • toggle: It is used to toggle the visibility of a collapsible element. 
  • show: It is used to show a collapsible element. 
  • hide: It is used to hide a collapsible element. 
  • dispose: It is used to dispose a collapsible element. 
  • getInstance: It is a static method that is used to get the collapsible element associated with the DOM.
  • getOrCreateInstance: It is a static method that is used to get the collapsible element associated with the DOM or create a new one if it is not present.

Syntax:

collapse.collapse_method();

Below examples illustrate the Bootstrap 5 Collapse Methods:

Example 1: In this example, we will show and hide the collapsible element using the "show" and "hide" methods given by the Bootstrap 5 collapse object.

Output:


Example 2: In this example, we will toggle and dispose of the collapsible element using the "toggle" and "dispose" methods given by the Bootstrap 5 Collapse object. Once we dispose of a collapsible element, we cannot use any methods given by Bootstrap 5 to collapse object as it gets destroyed in the DOM. 

Output:

Reference: https://getbootstrap.com/docs/5.0/components/collapse/#methods

Comment

Explore