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 Usage Methods
Next article icon

Bootstrap 5 Tooltips using function with popperConfig

Last Updated : 21 Jun, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report

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 element and options attribute to embed tooltip to HTML element.

Syntax:

var tooltip = new bootstrap.Tooltip(Element, {      popperConfig : <function>|null|object  })

From the above syntax, we can observe that popperConfig can be of the type object or function:

  • When popperConfig is an object:
 

Syntax:

popperConfig : {modifiers : array , placement : string}

Parameters:

  • modifiers: It is used to modify the working of the tooltip.
  • placement: It takes values like 'auto', 'auto-start', 'auto-end', 'top', 'top-start', 'top-end', 'bottom', 'bottom-start', 'bottom-end', 'right', 'right-start', 'right-end', 'left', 'left-start', 'left-end' to change the position of the tooltip.
  • When popperConfig is a function:

Syntax:

popperConfig : (defaultPopperConfig)=>{ ... }

Parameter:

  1. defaultPopperConfig: It is the default popper configuration.

Steps to add a tooltip with popperConfig:

Step 1: Create an HTML page with Bootstrap CDN

<script src=  "https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"           integrity=  "sha384-geWF76RCwLtnZ8qwWowPQNguL3RmwHVBC9FhGdlKrxdiJJigb/j/68SIy3Te4Bkz"           crossorigin="anonymous">  </script>  <link href=  "https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"         rel="stylesheet"         integrity=  "sha384-9ndCyUaIbzAi2FUVXJi0CjmCapSmO7SnpJef0486qhLnuZ2cdeRhO02iuK6FUUVM"         crossorigin="anonymous">

Step 2: Add a button with data attribute to create a tooltip

<button id="example"           data-bs-toggle="tooltip"           class="btn btn-primary"           title="tooltip">          Tooltip Button  </button>

Step 3: Add a script that selects the above button and modifies its tooltip features

<script>      var example = document.getElementById("example");      var tooltip = new bootstrap.Tooltip(example,{          popperConfig : ()=>{ ... }      })  </script>

Example 1: In this example, we will print the defaultPopperConfig which represents the default popper configuration of the popper framework.

HTML
<!DOCTYPE html> <html lang="en">  <head>     <meta charset="UTF-8">     <meta name="viewport"            content="width=device-width,                     initial-scale=1.0">     <link href= "https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"            rel="stylesheet"           integrity= "sha384-9ndCyUaIbzAi2FUVXJi0CjmCapSmO7SnpJef0486qhLnuZ2cdeRhO02iuK6FUUVM"           crossorigin="anonymous">     <script src= "https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"             integrity= "sha384-geWF76RCwLtnZ8qwWowPQNguL3RmwHVBC9FhGdlKrxdiJJigb/j/68SIy3Te4Bkz"             crossorigin="anonymous">     </script> </head>  <body class="p-5">     <h1 class="text-success">         GeeksforGeeks     </h1>     <h3 class="text-break">         Bootstrap 5 Tooltips Using          function with popperConfig     </h3>     <button id="example"              type="button"              class="btn btn-secondary"              data-bs-toggle="tooltip"              data-bs-placement="top"             title="Tooltip in Boostrap">         Tooltip Button     </button> </body>  <script>     var example = document.getElementById('example')     var tooltip = new bootstrap.Tooltip(example, {         popperConfig: (dpc) => {             console.log(dpc)             return dpc;         }     }) </script>  </html> 

Output:

ezgifcom-video-to-gif(6).gif

Example 2: In this example, we will toggle the placement property of the popper configuration between the top and bottom using popperConfig. Here, we have created a <script> tag & declare a variable by the name toggle and initialize it to 0. Now, Select the button in HTML code and add the below code inside bootstrap.Tooltip

(toggle)? dpc.placement = "bottom" : dpc.placement = "top"  toggle = !toggle; // declare a variable outside this function  return dpc;

The above code toggles the tooltip between the top and bottom every time the user hovers the button.

HTML
<!DOCTYPE html> <html lang="en">  <head>     <meta charset="UTF-8">     <meta name="viewport"            content="width=device-width,                     initial-scale=1.0">     <link href= "https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"            rel="stylesheet"           integrity= "sha384-9ndCyUaIbzAi2FUVXJi0CjmCapSmO7SnpJef0486qhLnuZ2cdeRhO02iuK6FUUVM"            crossorigin="anonymous">     <script src= "https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"             integrity= "sha384-geWF76RCwLtnZ8qwWowPQNguL3RmwHVBC9FhGdlKrxdiJJigb/j/68SIy3Te4Bkz"             crossorigin="anonymous">     </script> </head>  <body class="p-5">     <h1 class="text-success">         GeeksforGeeks     </h1>     <h3 class="text-break">         Bootstrap 5 Tooltips Using         function with popperConfig     </h3>     <button id="example"              type="button"              class="btn btn-secondary"             data-bs-toggle="tooltip"              data-bs-placement="top"             title="Tooltip in Boostrap">         Button with toggling tooltip     </button> </body> <script>     var example = document.getElementById('example')     var toggle = 0     var tooltip = new bootstrap.Tooltip(example, {         popperConfig: (dpc) => {             (toggle) ? dpc.placement = "bottom" : dpc.placement = "top"             toggle = !toggle;             return dpc;         }     }) </script>  </html> 

Output:

ezgifcom-video-to-gif(8).gif

Reference: https://getbootstrap.com/docs/5.0/components/tooltips/#using-function-with-popperconfig


Next Article
Bootstrap 5 Tooltips Usage Methods
author
nikhilkalburgi
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