VOOZH about

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

⇱ Bootstrap 5 Scrollspy getOrCreateInstance() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Bootstrap 5 Scrollspy getOrCreateInstance() Method

Last Updated : 23 Jul, 2025

Bootstrap 5 Scrollspy 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.

Syntax:

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

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

Return Value: This method returns the current Scrollspy instance to the caller. If no instance is yet created, it creates one.

Example 1: The code demonstrates how we can implement the getOrCreateInstance() method on a Scrollspy using JavaScript on a Scrollspy with a navbar.

Output:


Example 2: The code demonstrates how to implement the usage of the getOrCreateInstance() method using JavaScript on a scroll spy in a Nested Side Navbar.

Output:

Reference: https://getbootstrap.com/docs/5.0/components/scrollspy/#getorcreateinstance

Comment
Article Tags:

Explore