Check if a jquery tools tooltip is already assigned to a component

↘锁芯ラ 提交于 2019-12-13 14:15:09

问题


I have a component to which I assign a tooltip upon first mouseenter (sort of a lazy assignment of tooltip to component)

I use the lazy approach since there are many tooltip'able components and I don't want to pre-assign the tooltips to all of them.

$(document).delegate(".tooltipable", "mouseenter", function () {
    $(this).tooltip(... options ...);
    $(this).tooltip().show(); // The tooltip will not appear on first `mouseenter` so I have to explicitly show it here
});

This works just fine. I would like to improve it so the tooltip will not be created on every mouseenter by checking if the tooltip was already created for this component.

How can that be done?

Thanks in Advance!


回答1:


You can try something like this.

$(document).delegate(".tooltipable", "mouseenter", function () {
    var $this = $(this);
    if(!$this.data("tooltipset")){
       $(this).tooltip(... options ...)
       .data("tooltipset", true);
    }
    $(this).tooltip().show(); // The tooltip will not appear on first `mouseenter` so I have to explicitly show it here
});


来源:https://stackoverflow.com/questions/8969192/check-if-a-jquery-tools-tooltip-is-already-assigned-to-a-component

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!