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?
相关问题
- How to fix IE ClearType + jQuery opacity problem i
- jQuery add and remove delay
- Include empty value fields in jQuery .serialize()
- Disable Browser onUnload on certain links?
- how to get selected text from iframe with javascri
For bootstrap 3.x
This seems like cleanest solution:
Show is used to make title update right away and not wait for tooltip to be hidden and shown again.
you can use this code to hide the tool tip change its title and show the tooltip again, when the ajax request returns successfully.
You can just change the
data-original-title
using the following code:This worked for me: (bootstrap 3.3.6; jquery=1.11.3)
The attribute
data-html="true"
allow to use html on the tooltip title.Just found this today whilst reading the source code. So
$.tooltip(string)
calls any function within theTooltip
class. And if you look atTooltip.fixTitle
, it fetches thedata-original-title
attribute and replaces the title value with it.So we simply do:
and sure enough, it updates the title, which is the value inside the tooltip.
Another way (see @lukmdo comment below):
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.