VOOZH about

URL: https://www.geeksforgeeks.org/bootstrap/bootstrap-5-list-group-getorcreateinstance-method/

⇱ Bootstrap 5 List group getOrCreateInstance() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Bootstrap 5 List group getOrCreateInstance() Method

Last Updated : 22 Jul, 2024

Bootstrap List group getOrCreateInstance() method is used to obtain the instance of a particular tab of the list Group. This method can work even when the instance is not pre-initialized and this method creates an instance if there isn't one available.

The List group tab's instance linked to a DOM element may be obtained using this static function or create one instance.

Syntax:

var tab-element = document
.getElementById("listGroup-tab-id");
var tooltip-instance = bootstrap.Tooltip
.getOrCreateInstance(tab-element);

Parameters: This method accepts an argument either an HTML element or its selector.

Return Value: This method returns the current Bootstrap 5 List group Tab instance to the caller. If no instance is yet created, it creates one.

Example 1: This example demonstrates how to implement the getOrCreateInstance() Method with the show() method. Here one tab's instance is created with the getOrCreateInstance() Method but the second tab's instance is pre-initialized.

Output:


Example 2: This example demonstrates how to implement the getOrCreateInstance() Method with the dispose() method. Here one tab's instance is pre-initialized but the second tab's instance gets created with the getOrCreateInstance() Method.

Output:

Reference: https://getbootstrap.com/docs/5.0/components/list-group/#getorcreateinstance

Comment
Article Tags:

Explore