Change Twitter Bootstrap Tooltip content on click

前端 未结 25 1363
情深已故
情深已故 2020-11-27 10:02

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

25条回答
  •  佛祖请我去吃肉
    2020-11-27 10:42

    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');
    

提交回复
热议问题