Change Twitter Bootstrap Tooltip content on click

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

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

提交回复
热议问题