I have a tooltip on an anchor element, that sends an AJAX request on click. This element has a tooltip (from Twitter Bootstrap). I want the tooltip content to change when the AJAX request returns successfully. How can I manipulate the tooltip after initiation?
31 Answers
Just found this today whilst reading the source code. So $.tooltip(string)
calls any function within the Tooltip
class. And if you look at Tooltip.fixTitle
, it fetches the data-original-title
attribute and replaces the title value with it.
So we simply do:
$(element).tooltip('hide')
.attr('data-original-title', newValue)
.tooltip('fixTitle')
.tooltip('show');
and sure enough, it updates the title, which is the value inside the tooltip.
A shorter way:
$(element).attr('title', 'NEW_TITLE')
.tooltip('fixTitle')
.tooltip('show');

- 30,436
- 41
- 178
- 315

- 4,615
- 1
- 14
- 4
-
5You can also change the title through the data('tooltip').options property, see http://stackoverflow.com/questions/10181847/how-to-change-placement-of-twitter-bootstrap-tooltip-placement-after-initializat – James McMahon Apr 21 '13 at 01:24
-
scroll down (or http://stackoverflow.com/a/20713610/1350306) to change text without closing/reopening the toolip. – ndreckshage Dec 20 '13 at 23:38
-
4Couldn't find documentation on 'fixTitle', so I guess not a good idea to use this!? ... – user2846569 Feb 23 '15 at 14:58
-
You can safely omit the call to fixTitle: $(element).attr('data-original-title', 'xyz') – Roy Hyunjin Han Sep 18 '15 at 15:39
-
Is there a way to update the text without manipulating the title-attribute? – molerat Nov 18 '15 at 12:29
-
I removed tooltip('hide') and tooltip('fixTitle'), and it worked still – sksallaj Feb 12 '16 at 01:37
-
27This actually didn't work for me, the tooltip switched values and then disappeared quickly. `$(element).attr('data-original-title', newValue).tooltip('show');` was the simplest working solution for me. – Gabe O'Leary Mar 18 '16 at 22:00
-
I was having trouble with the tooltip after using both methods (it was disappearing a not coming back again), it was basically because of the native focus so adding ``$element.trigger('focusout')`` fixed that problem for me. – jac1013 Mar 02 '17 at 21:38
-
In my case @lukmdo solution didn't work properly. I still could see the old title for a moment so the `tooltip('hide')` was useful. – Geoffroy CALA Mar 21 '17 at 14:49
-
This works in firefox, chrome, IE and Edge, "$(element).attr('data-original-title', newValue).tooltip('show');" , was indeed the simplest working solution, thanks. – César León Sep 26 '17 at 13:58
-
5@fsasvari in bootstrap 4 just change it to '_fixTitle' – Jamie M Jun 20 '18 at 14:25
-
I am using Bootstrap v4.1.2 and I had to use _fixTitle instead of fixTitle – Mubramaj Jul 20 '18 at 21:52
-
1Bootstrap 4 - noted below - use .tooltip('update'); – Ben in CA Nov 14 '19 at 16:18
-
$(element).attr('title', 'NEW_TITLE') is enough to update the title – Fouad Apr 30 '20 at 14:13
-
In my case works without ".tooltip('fixTitle')" just in this way: $(element).tooltip('hide') .attr('data-original-title', newValue) .tooltip('show'); – Vikcen Jun 01 '22 at 17:01
In Bootstrap 3 it is sufficient to call elt.attr('data-original-title', "Foo")
as changes in the "data-original-title"
attribute already trigger changes in the tooltip display.
UPDATE: You can add .tooltip('show') to show the changes immediately, you need not to mouseout and mouseover target to see the change in the title
elt.attr('data-original-title', "Foo").tooltip('show');

- 1,229
- 17
- 31

- 2,025
- 1
- 18
- 23
-
4It not applies changes immediately, you need to mouseout and mouseover target to see the new title text – Lev Lukomsky Sep 25 '15 at 14:00
-
9This is actually the best answer and you can add `.tooltip('show');` to get it to show after the update – Jared Oct 28 '15 at 02:11
-
This is the only solution (out of many tried) that seemed to just work (bs3). Nice solution for sure! – jyoseph Jun 02 '16 at 18:33
-
3
-
why it didn't work when i use single quote as in second parameter around `'Foo'` like `.attr('data-original-title', 'Foo')` ?? – Hammad Sajid May 17 '19 at 07:47
-
Since Bootstrap v5 it is `data-bs-original-title` instead of `data-original-title` – JV conseil May 27 '22 at 22:34
-
the solution rise another issue - tooltip does't get hide on mouseover – Alexey Sh. Mar 06 '23 at 04:00
Here is update for the Bootstrap 4:
var title = "Foo";
elt.attr('data-original-title', title);
elt.tooltip('update');
elt.tooltip('show');
But the best way is to do like this:
var title = "Foo";
elt.attr('title', title);
elt.attr('data-original-title', title);
elt.tooltip('update');
elt.tooltip('show');
or inline:
var title = "Foo";
elt.attr('title', title).attr('data-original-title', title).tooltip('update').tooltip('show');
From the UX side you just see that text is changed with no fading or hide/show effects and there is no needs for the _fixTitle
.

- 6,249
- 6
- 45
- 78
-
1The solution worked for me, thanks! In general, please note that you can only update tooltips which are enabled. So in case you have manually disabled a tooltip, you have to re-enable it by using elt.tooltip('enable') before updating it. – Alexander Oct 13 '21 at 14:27
you can update the tooltip text without actually calling show/hide:
$(myEl)
.attr('title', newTitle)
.tooltip('fixTitle')
.tooltip('setContent')

- 1,756
- 15
- 17
-
3
-
1yeah, `setContent` and `show` does the trick! you can change `data-original-title` directly instead of using `fixTitle` – brauliobo Sep 19 '15 at 21:56
-
-
for Bootstrap 4:
$(element).attr("title", "Copied!").tooltip("_fixTitle").tooltip("show").attr("title", "Copy to clipboard").tooltip("_fixTitle");

- 151
- 1
- 2
heres a nice solution if you want to change the text without closing and reopening the tooltip.
$(element).attr('title', newTitle)
.tooltip('fixTitle')
.data('bs.tooltip')
.$tip.find('.tooltip-inner')
.text(newTitle)
this way, text replaced without closing tooltip (doesnt reposition, but if you are doing a one word change etc it should be fine). and when you hover off + back on tooltip, it is still updated.
**this is bootstrap 3, for 2 you probably have to change data/class names

- 853
- 9
- 20
-
5
-
Did that: `$(element).attr('title', newTitle).tooltip('fixTitle').parent().find('.tooltip .tooltip-inner').text(newTitle);` – Augustin Riedinger Jan 20 '15 at 10:58
-
I'm updating a tooltip on a neighbouring element when typing into a text field, and the tooltip is disappearing for me with this code when I press a key. – tremby Apr 06 '15 at 11:23
-
Thanks for this. The only problem with this solution is that it seems to mess up tooltip position after text change. – Wojciech Zylinski Apr 26 '15 at 22:47
This works if the tooltip has been instantiated (possibly with javascript):
$("#tooltip_id").data('tooltip').options.title="New_value!";
$("#tooltip_id").tooltip('hide').tooltip('show');

- 121
- 1
- 3
-
7With bootstrap 3, it becomes `$('#tooltip_id').data('bs.tooltip').options.title = 'New_value!';` – ajbeaven Oct 11 '13 at 19:16
-
Hey relational, could you change your answer to reflect the comments corrections? Thanks. – dessalines Sep 09 '15 at 14:13
Bootstrap 4
$('#topic_1').tooltip('dispose').tooltip({title: 'Goodbye'}).tooltip('show')
https://getbootstrap.com/docs/4.1/components/tooltips/#tooltipdispose
$('#topic_1').tooltip({title: 'Hello'}).tooltip('show');
setTimeout( function() {
$('#topic_1').tooltip('dispose').tooltip({title: 'Goodbye'}).tooltip('show');
}, 5000);
#topic_1 {
border: 1px solid red;
margin: 50px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/css/bootstrap.min.css" integrity="sha384-Smlep5jCw/wG7hdkwQ/Z5nLIefveQRIY9nfy6xoR1uRYBtpZgI6339F5dgvm/e9B" crossorigin="anonymous">
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/js/bootstrap.min.js" integrity="sha384-o+RDsa0aLu++PJvFqy8fFScvbHFLtbvScb8AjopnFD+iEQ7wo/CG0xlczd+2O/em" crossorigin="anonymous"></script>
<div id="topic_1">Topic 1</div>
For bootstrap 3.x
This seems like cleanest solution:
$(element)
.attr('data-original-title', 'New title').tooltip('show')
Show is used to make title update right away and not wait for tooltip to be hidden and shown again.

- 81
- 1
- 2
You can just change the data-original-title
using the following code:
$(element).attr('data-original-title', newValue);

- 743
- 2
- 9
- 29

- 1,520
- 2
- 19
- 35
Bootstrap 5 doesn't have fixTitle
or _fixTitle
anymore, so I had to dispose the entire Tooltip object and reconstruct it:
$('a.copy').click(function() {
var tt = bootstrap.Tooltip.getInstance(this);
tt.dispose();
this.setAttribute('title', 'Copied!')
tt = bootstrap.Tooltip.getOrCreateInstance(this);
tt.show();
}

- 141
- 3
- 5
The following worked the best for me, basically I'm scrapping any existing tooltip and not bothering to show the new tooltip. If calling show on the tooltip like in other answers, it pops up even if the cursor isn't hovering above it.
The reason I went for this solution is that the other solutions, re-using the existing tooltip, led to some strange issues with the tooltip sometimes not showing when hovering the cursor above the element.
function updateTooltip(element, tooltip) {
if (element.data('tooltip') != null) {
element.tooltip('hide');
element.removeData('tooltip');
}
element.tooltip({
title: tooltip
});
}

- 65,625
- 67
- 195
- 317
-
1
-
1If you're using boostrap3 you need to use `data('bs.tooltip')` instead of `data('tooltip')` – Jun 05 '14 at 19:31
Bootstrap 5.3
Bootstrap version 5.3
now has the setContent
method to change tooltip title after initialization. https://getbootstrap.com/docs/5.3/components/tooltips/#methods
var tooltip = bootstrap.Tooltip.getInstance('#elementId');
tooltip.setContent({ '.tooltip-inner': 'another title' });

- 41
- 2
-
It is strange, using setContent only hide my tooltip in my case without any error. – probitaille Nov 24 '22 at 18:15
In bootstrap 4 I just use $(el).tooltip('dispose');
then recreate as normal. So you can put the dispose before a function that creates a tooltip to be sure it doesn't double up.
Having to check the state and tinker with values seems less friendly.

- 3,157
- 2
- 22
- 28
-
Should we call $(el).tooltip('dispose') before or after updating the tooltip title ? – Fifi Sep 03 '18 at 09:53
-
@imabot dispose of old tooltip, then recreate with new data. If your tooltips are complex you may want to retrieve or otherwise store the initial config so you can just recreate with that config + new values. Hope that makes sense. – Martin Lyne Sep 03 '18 at 21:11
You can set content on tooltip call with a function
$("#myelement").tooltip({
"title": function() {
return "<h2>"+$("#tooltipcontainer").html()+"</h2>";
}
});
You don't have to use only the title of the called element.

- 21
- 1
Thanks this code was very helpful for me, i found it effective on my projects
$(element).attr('title', 'message').tooltip('fixTitle').tooltip('show');

- 29
- 1
I change the title in tooltip dynamicaly with ajax.
first just enable the tooltips:
$('[data-toggle="tooltip"]').tooltip()
Then change the title attribute, then re init the tooltip
$("#foo").attr('title','TheNewTitle');
$('[data-toggle="tooltip"]').tooltip('dispose');
$('[data-toggle="tooltip"]').tooltip()

- 41
- 1
Do NOT use .tooltip('show')
if you have multiple tooltip that dynamically change, see example below, hover all element below for 1 second then mouseout, you will see unexpected result
$('[data-toggle="tooltip"]').tooltip()
$('[data-toggle="tooltip"]').mouseover((e) => {
let self = $(e.target);
setTimeout(function() { // ajax call
self.attr('data-original-title', 'New Value of ' + self.text())
.tooltip('show');
}, 3000);
})
span{margin: 20px;font-weight: bold}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/css/bootstrap.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/js/bootstrap.min.js"></script>
<span data-toggle="tooltip" title="Text 1">Text 1</span>
<span data-toggle="tooltip" title="Text 2">Text 2</span>
<span data-toggle="tooltip" title="Text 3">Text 3</span>
the better way is by editing data-original-title
and .tooltip-inner
$('[data-toggle="tooltip"]').tooltip()
$('[data-toggle="tooltip"]').mouseover((e) => {
let self = $(e.target);
setTimeout(function() { // ajax call
let newValue = 'New Value of ' + self.text();
self.attr('data-original-title', newValue)
$('.tooltip-inner').html(newValue)
}, 3000);
})
span{margin: 20px;font-weight: bold}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/css/bootstrap.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/js/bootstrap.min.js"></script>
<span data-toggle="tooltip" title="Text 1">Text 1</span>
<span data-toggle="tooltip" title="Text 2">Text 2</span>
<span data-toggle="tooltip" title="Text 3">Text 3</span>

- 6,002
- 2
- 26
- 40
Destroy any pre-existing tooltip so we can repopulate with new tooltip content
$(element).tooltip("destroy");
$(element).tooltip({
title: message
});

- 326
- 1
- 3
- 11
I couldn't get any of the answers working, here's a workaround:
$('#'+$(element).attr('aria-describedby')+' .tooltip-inner').html(newTitle);

- 3,264
- 1
- 25
- 40
For BS4 (and BS3 with minor changes) .. after hours of searching and trials, i came up with the most reliable solution for this problem and it even solves the problem of opening more than one (tooltip or popover) at the same time, and the problem of opening automatically after losing focus, etc.
$('[data-toggle="tooltip"]').tooltip({
trigger: 'hover'
}).on('shown.bs.tooltip', function() {
var link = $(this);
var data = '';
data += '<ul style="list-style-type:none;margin:0;padding:0;text-align:left;font-size:12px">';
data += ' <li>Sherif Salah</li>';
data += ' <li>Muhammad Salah</li>';
data += ' <li>and a gazillion more...</li>';
data += '</ul>';
link.attr('data-original-title', data);
setTimeout(function() {
if (link.is(':hover')) {
link.tooltip("dispose").tooltip("show");
}
}, 1000);
});
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" />
</head>
<body>
<div class="card">
<div class="card-body text-center">
<a href="JavaScript:void(0);" class="btn btn-sm btn-link" data-toggle="tooltip" data-placement="top" data-html="true" title="Loading...">gazillion</a>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
</body>
</html>

- 2,085
- 2
- 9
- 21
I only tested this in bootstrap 4 & w/o calling .show()
el.tooltip('hide').attr('data-original-title', 'message');

- 367
- 1
- 4
- 13
Want to change tooltip content/title onclick like bootstrap docs. Did you notice when you copy a code example there? I'm using Bootstrap v5
here...
<span id="tooltip" class="btn btn-outline-primary" data-bs-toggle="tooltip" data-bs-placement="top"
title="Tooltip content">Tooltip</span>
Make sure you've enabled the Bootstrap5 tooltip before going to the next step
$('#tooltip').click(function() {
$(this).attr('data-original-title', 'Content changed!').tooltip('show');
$(this).attr('data-original-title', 'Tooltip content');
});
When you hover on this span element, it will show Tooltip content. When you click on it, this will change to Content changed! and will return to default title Tooltip content.

- 232
- 4
- 12
I think Mehmet Duran is almost right, but there were some problems when using multiple classes with the same tooltip and their placement. The following code also avoids js errors checking if there is any class called "tooltip_class". Hope this helps.
if (jQuery(".tooltip_class")[0]){
jQuery('.tooltip_class')
.attr('title', 'New Title.')
.attr('data-placement', 'right')
.tooltip('fixTitle')
.tooltip('hide');
}

- 612
- 8
- 11
Change the text by altering the text in the element directly. (does not update the tooltip position).
$('.tooltip-inner', $element.next()).html(newHtml);
$('.tooltip-inner', $element.next()).text(newText);
Change the text by destroying the old tooltip, then creating and showing a new one. (Causes the old one to fade out and the new one to fade in)
$element
.tooltip('destroy')
.tooltip({
// Repeat previous options.
title: newText,
})
.tooltip('show');
I'm using the top method to both animate the "Saving." message (using  
so the tooltip does not change in size) and to change the text to "Done." (plus padding) when the request completes.
$element.tooltip({
placement: 'left',
title: 'Saving...',
trigger: 'manual',
}).tooltip('show');
var parent = $element.parent();
var interval_id = setInterval(function(){
var text = $('.tooltip-inner', parent).html();
switch(text) {
case 'Saving. ': text = 'Saving.. '; break;
case 'Saving.. ': text = 'Saving...'; break;
case 'Saving...': text = 'Saving. '; break;
}
$('.tooltip-inner', parent).html(text);
}, 250);
send_request( function(){
// When the request is complete
clearInterval(interval_id);
$('.tooltip-inner', parent).html('Done. ');
setTimeout(function() {
$element.tooltip('hide');
}, 1500 /* Show "Done." for a bit */);
});

- 12,963
- 4
- 59
- 80
This worked for me: (bootstrap 3.3.6; jquery=1.11.3)
<a id="alertTooltip" href="#" data-html="true" class="tooltip" data-toggle="tooltip" title="Tooltip message"></a>
<script>
$('#alertTooltip').attr('title', "Tooltip new <br /> message").tooltip('fixTitle');
</script>
The attribute data-html="true"
allow to use html on the tooltip title.
With Tooltip object Boostrap :
$(element).attr('data-original-title', 'New value');
$(element).data('bs.tooltip').tip().find('.tooltip-inner').text('New value');

- 978
- 10
- 19
if you have set the title attribute in HTML then use on click of the icon or button $(this).attr('title',newValue);

- 411
- 4
- 4
you can use this code to hide the tool tip change its title and show the tooltip again, when the ajax request returns successfully.
$(element).tooltip('hide');
$(element).attr('title','this is new title');
$(element).tooltip('fixTitle');
setTimeout(function() { $(element).tooltip('show');}, 500);

- 1,208
- 2
- 17
- 30
I'm using this easy way out:
$(document).ready(function() {
$("#btn").prop('title', 'Click to copy your shorturl');
});
function myFunction(){
$(btn).tooltip('hide');
$(btn).attr('data-original-title', 'Test');
$(btn).tooltip('show');
});

- 73
- 4
- 15
$(this).attr('data-original-title', 'click here to publish')
.tooltip('fixTitle')
.tooltip('show');
Useful if you need to change a tooltip's text after it has been initialized with attr 'data-original-title'.

- 9
- 1
- 1