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 th
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');
you can update the tooltip text without actually calling show/hide:
$(myEl)
.attr('title', newTitle)
.tooltip('fixTitle')
.tooltip('setContent')
I couldn't get any of the answers working, here's a workaround:
$('#'+$(element).attr('aria-describedby')+' .tooltip-inner').html(newTitle);
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);
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.
$(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'.