Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • BS5 Tutorial
  • BS5 Interview Questions
  • BS5 Layout
  • BS5 Content
  • BS5 Components
  • BS5 Helpers
  • BS5 Utilities
  • BS4 Tutorial
  • BS Tutorial
  • Bootstrap Cheatsheet
  • Tailwind
  • CSS Frameworks
  • HTML Formatter
Open In App
Next Article:
Bootstrap 5 Tooltips getOrCreateInstance() Method
Next article icon

Bootstrap 5 Tooltips getInstance() Method

Last Updated : 31 Jul, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Bootstrap Tooltips getInstance() Method is used to obtain the instance of tooltips while the tooltips are being used. This method can only work after the instance is pre-initialized. The tooltip instance linked to a DOM element may be obtained using this static function.

Syntax:

var tooltip-element = 
document.getElementById("tooltip-id");
var tooltip-instance = bootstrap
.Tooltip.getInstance(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.

Example 1: The code example below demonstrates how to implement the getInstance() method using JavaScript on Tooltips on top and right.

HTML
<!doctype html> <html lang="en">  <head>     <link href= "https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"       rel="stylesheet">     <script src= "https://code.jquery.com/jquery-3.5.1.min.js">    </script>     <script src= "https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js">     </script> </head>  <body class="container text-center">     <h1 class="m-4 text-success">         GeeksforGeeks     </h1>     <h4 class="ms-4">         Bootstrap 5 Tooltips getInstance() Method     </h4>     <div class="container mt-4 p-4">         <button type="button"                 class="btn btn-success ms-5 me-5"                  id="t-tooltip"                  data-bs-placement="top"                 title="This is a Tooltip on Top">             Top Tooltip         </button>         <button type="button"                  class="btn btn-success ms-5 me-5"                  id="r-tooltip"                  data-bs-placement="right"                 title="This is a Tooltip on Right">             Right Tooltip         </button>     </div>     <div class="container mt-4 p-2">         <button type="button"                  class="btn btn-danger"                  id="instanceBtn_1">             Get Instance of top Tooltip         </button>         <button type="button"                  class="btn btn-danger ms-1"                  id="instanceBtn_2">             Get Instance of right Tooltip         </button>     </div>     <script>         document.addEventListener("DOMContentLoaded",                                    function () {             var btn_1 =                  document.getElementById("instanceBtn_1");             var btn_2 =                  document.getElementById("instanceBtn_2");             var element_1 =                  document.getElementById("t-tooltip");             var element_2 =                  document.getElementById("r-tooltip");              // Trigger the tooltip             var tooltip_1 =                  new bootstrap.Tooltip(element_1);             var tooltip_2 =                  new bootstrap.Tooltip(element_2);              // Get tooltip instance on button click             btn_1.addEventListener("click", function () {                 var tooltipInstance_1 =                      bootstrap.Tooltip.getInstance(element_1);                 console.log(tooltipInstance_1);             });                        // Get tooltip instance on button click             btn_2.addEventListener("click", function () {                 var tooltipInstance_2 =                      bootstrap.Tooltip.getInstance(element_2);                 console.log(tooltipInstance_2);             });         });     </script> </body>  </html> 

Output:


Example 2: The code example below demonstrates how to implement the getInstance() method using JQuery on Tooltips with anchor tags on the bottom and left.

HTML
<!doctype html> <html lang="en">  <head>     <link href= "https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"      rel="stylesheet">     <script src= "https://code.jquery.com/jquery-3.5.1.min.js">     </script>     <script src= "https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js">    </script> </head>  <body class="container text-center">     <h1 class="m-4 text-success">           GeeksforGeeks       </h1>     <h4 class="ms-4">           Bootstrap 5 Tooltips getInstance() Method       </h4>     <div class="container mt-4 p-4">         <a href= "https://www.geeksforgeeks.org/"             id="b-tooltip"            data-bs-placement="bottom"            title="This is the Bottom placed tooltip">                  Hover to open Bottom Tooltip         </a>         <a href= "https://www.geeksforgeeks.org/"             class="ms-5"             id="l-tooltip"            data-bs-placement="left"            title="This is the Left placed tooltip">                  Hover to open Left Tooltip         </a>     </div>     <div class="container mt-4 p-2">         <button type="button"                  class="btn btn-danger"                  id="instanceBtn_1">             Get Instance of Bottom Tooltip         </button>         <button type="button"                  class="btn btn-danger ms-4"                  id="instanceBtn_2">             Get Instance of Left Tooltip         </button>     </div>     <script>         $(document).ready(function () {                        // Trigger the first tooltip             $("#b-tooltip").tooltip();                        // Trigger the second tooltip             $("#l-tooltip").tooltip();              // Get first tooltip instance on button click             $("#instanceBtn_1").click(function () {                 var tooltip_1 = bootstrap.                     Tooltip.getInstance($("#b-tooltip")[0]);                     console.log(tooltip_1);             });                        // Get second tooltip instance on button click             $("#instanceBtn_2").click(function () {                 var tooltip_2 = bootstrap.                     Tooltip.getInstance($("#l-tooltip")[0]);                     console.log(tooltip_2);             });         });     </script> </body>  </html> 

Output:


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


Next Article
Bootstrap 5 Tooltips getOrCreateInstance() Method

P

priyanshuchatterjee01
Improve
Article Tags :
  • Web Technologies
  • Bootstrap
  • Bootstrap-5

Similar Reads

  • Bootstrap 5 Tooltips
    A Tooltip is used to provide interactive textual hints to the user about the element when the mouse pointer moves over. The tooltip is quite useful for displaying the description of different elements on the webpage. To create a tooltip, we need to add the data-bs-toggle="tooltip" attribute to an el
    3 min read
  • Bootstrap 5 Enable Tooltips Everywhere
    Bootstrap 5 Tooltips can be enabled everywhere by first creating a list of all the tooltips and then enabling each of them. All the tooltips have an attribute named "data-bs-toggle" set to "tooltip". This attribute can be used to select all the tooltips using the document.querySelectorAll() method.
    2 min read
  • Bootstrap 5 Tooltips Usage
    Bootstrap 5 Tooltips usage is used to create the markup and the text on the elements when required, and the tooltip created is placed after the element that was triggered. Using Javascript to launch Tooltips: var example = document.getElementById('...') var ... = new bootstrap.Tooltip(example, value
    3 min read
  • Bootstrap 5 Tooltips Usage Markup
    Bootstrap 5 Tooltip is one of the components which provide small, interactive, textual hints for elements. They are used to provide additional information about a specific element when the user hovers over it or focuses on it. Bootstrap 5 Tooltips Usage Markup: The markup required for the tooltips a
    2 min read
  • Bootstrap 5 Tooltips Usage Disabled Elements
    Bootstrap 5 Tooltips are a JavaScript plugin that allows you to add small, interactive, text-based hints to elements on your web page. They are displayed when the user hovers over, clicks on, or focuses on the element. Tooltips can be used to provide additional information about an element, such as
    2 min read
  • Bootstrap 5 Tooltips Usage Options
    Bootstrap 5 Tooltip usage options can be passed through the data attributes or via JavaScript. To pass the options through data attributes we have to append the option name with the data-bs for example data-bs-animation="true". Some of the many options available are:animation: It is used to apply an
    4 min read
  • Bootstrap 5 Tooltips using function with popperConfig
    Bootstrap 5 Tooltips Using function with popperConfig facilitates an interface that allows us to change the default Popper Configuration. Popper is a framework that helps us to create popups in websites. PopperConfig is actually an option in bootstrap.Tooltip class that can be initialized with an el
    3 min read
  • Bootstrap 5 Tooltips Usage Methods
    Bootstrap 5 Tooltips facilitates some pre-defined methods that we can use to trigger different types of functionalities in tooltips. The methods can be implemented using JavaScript and JQuery. Bootstrap 5 Tooltips Usage Methods: The Tooltips Methods with their function are given below: show(): The s
    4 min read
  • Bootstrap 5 Tooltips show() Method
    Bootstrap 5 Tooltip is a UI element that shows some extra information when the user hovers over or focuses on a tooltip-enabled element. The Tooltip show() method is used to show an element's tooltip. The Tooltip having the zero title length will not be visible. Syntax: const tooltip = new bootstrap
    2 min read
  • Bootstrap 5 Tooltip hide() Method
    Bootstrap 5 Tooltip is used to show some extra information to the user when the user hovers over the element. The Tooltip hide() method is used to hide a visible tooltip. Syntax: bootstrap.Tooltip.getInstance("#tooltip-ID").hide();Parameters: This method accepts a single parameter that holds the too
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences