Change Twitter Bootstrap Tooltip content on click

前端 未结 25 1355
情深已故
情深已故 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

    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.

提交回复
热议问题