VOOZH about

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

⇱ Bootstrap 5 Tooltips getOrCreateInstance() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Bootstrap 5 Tooltips getOrCreateInstance() Method

Last Updated : 23 Jul, 2025

Bootstrap Tooltips getOrCreateInstance() method is used to obtain the instance of tooltips while the tooltips are being used. This method can work even when the instance is not pre-initialized and this method creates an instance if there isn't one available.

Syntax:

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

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

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

Example 1: The code example below demonstrates how to implement the getOrCreateInstance() method using jQuery on Tooltips on the bottom and left. The bottom tooltip instance is pre-initialized and the other one gets initialized.

Output:

Example 2: The code example below demonstrates how to implement the getOrCreateInstance() method using jQuery on Tooltips with anchor tags on the top and right. The top tooltips' instance is pre-initialized and the other one gets initialized.

Output:

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

Comment
Article Tags:

Explore