question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bootstrap 5.2 update Tooltip Title with Javascript is not working

See original GitHub issue

Prerequisites

Describe the issue

Hello Update Tooltip Title with Javascript was working fine in version v5.1.3 of bootstrap.bundle.js, but now it is not working using version v5.2.0-beta1 of the same file.

This is the code I use

$(function () {
 $('[data-toggle="tooltip"]').tooltip()
  document.getElementById('tt').setAttribute('data-bs-original-title', 'New Tooltip Title');
})

stackoverflow: Bootstrap 5 update Tooltip Title with Javascript

Reduced test cases

with version 5.0.0 https://codepen.io/moshair/pen/ExQweey

with version 5.2 beta https://codepen.io/moshair/pen/zYREJmq

What operating system(s) are you seeing the problem on?

Windows

What browser(s) are you seeing the problem on?

Firefox

What version of Bootstrap are you using?

v5.2.0-beta1

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5

github_iconTop GitHub Comments

4reactions
Supporticcommented, May 31, 2022

@moshair I see what you are trying to do. I downloaded the source code and unfortunately it seems that they dropped support for that attribute. Reading the source code also indicates that this attribute was never documented and essentially was never meant to be used. https://github.com/twbs/bootstrap/blob/v5.1.3/js/src/tooltip.js#L237

Now you should be able to use the function setContent on tooltips like documented here. https://getbootstrap.com/docs/5.2/components/tooltips/#methods

Your new way of changing it is now the following:

let carsArr = ["", "Saab", "Volvo", "BMW"];

function Showtt(self,v) {
  const tooltip = bootstrap.Tooltip.getInstance(self)
  tooltip.setContent({'.tooltip-inner': carsArr[v]}) // key is the class container of the content
}

and your HTML element

<span id='tt_1' class="btn btn-secondary" onmouseover="Showtt(this,1)" data-bs-toggle="tooltip" data-bs-placement="top" title="1">1</span>

chrome_heaPxrxYlw

1reaction
Supporticcommented, May 30, 2022

What is your goal? Keep the old title or just overwrite it?

dublicate to: https://github.com/twbs/bootstrap/issues/32944

I couldn’t find any line in the documentation talking about the data-bs-original-title attribute. The problem you mentioned occured in bootstrap 4 according to the stackoverflow link you linked. The title attribut is now responsible for displaying the tooltip content. If you first set the title and then initialize the tooltip, everything is working.

document
  .getElementById("tt")
  .setAttribute("data-bs-title", "New Tooltip Title");
new bootstrap.Tooltip(jQuery('[data-toggle="tooltip"]'));

This was a solution mentioned in your stackoverflow link: https://stackoverflow.com/a/65863062/10192487 However it should be possible to use data-bs-title because the options are saying that you can use the prefix data-bs- to adjust the options which working since 5.1 or 5.2. [doc ref]

Your examples seem to be a bit odd.

Your 5.0 example includes beta source Links which might not represent a stable behaviour. Since 5.0 Tooltips are getting initialized like this new bootstrap.Tooltip(jQuery('[data-toggle="tooltip"]')); [doc ref]

Bootstrap should according to documentation only initialize with jQuery by searching for the jQuery Object on window instead of $. [doc ref]

Both of your button markups include the data-placement attribute which should be data-bs-placement in 5.0. [doc ref]

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bootstrap 5 update Tooltip Title with Javascript - Stack Overflow
You can update the tooltip title by changing the data-bs-original-title attribute.
Read more >
Tooltips · Bootstrap v5.2
Documentation and examples for adding custom Bootstrap tooltips with CSS and JavaScript using CSS3 for animations and data-bs-attributes for local title storage ...
Read more >
How to Create Tooltips with Bootstrap 5 - Tutorial Republic
Tooltips can be enabled via JavaScript — just call the tooltip() Bootstrap method with the id , class or any CSS selector of...
Read more >
Tooltips not showing up with latest version of Bootstrap
In the 4.x version, Bootstrap Tooltips were not enabled by default. You had to manually add the javascript. But as of BSS 5.x,...
Read more >
Bootstrap 5 Tooltip - W3Schools
To create a tooltip, add the data-bs-toggle="tooltip" attribute to an element. ... Note: Tooltips must be initialized with JavaScript to work. The following...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found