简体   繁体   English

[Tooltipster Plugin] - 知道div是否已经有tooltipster

[英][Tooltipster Plugin]- Know if div already have tooltipster

I'm using this plugin http://iamceege.github.io/tooltipster/ . 我正在使用这个插件http://iamceege.github.io/tooltipster/

It is possible know if a HTML already have the tooltipster initialized? 有可能知道HTML是否已经初始化了工具提示器?

I wanna know because sometimes i need to change the text of the tooltip, and for do that, i need to destroy the tooltipster, change the attribute title of the HTML object, and initialize again. 我想知道,因为有时我需要更改工具提示的文本,为此,我需要销毁工具提示器,更改HTML对象的属性标题,然后再次初始化。 Like this: 像这样:

$(this).tooltipster('destroy').attr("title", data.fields[i].value).tooltipster();

You can use the API: 您可以使用API​​:

Check if the element already has tooltipster: 检查元素是否已经有工具提示符:

$(...).hasClass("tooltipstered");

$(...).tooltipster('content', myNewContent);

Accepted solution does not work on SVG elements with tooltipster v4.1.6. 使用tooltipster v4.1.6,接受的解决方案不适用于SVG元素。 This is how I solved it: 这就是我解决它的方式:

if ($.tooltipster.instances($(node)).length == 0) {
    //it is NOT tooltipstered
}
else {
    //it is tooltipstered
}

Use .hasClass to check if it has the tooltipstered class 使用.hasClass检查它是否具有tooltipstered类

var divToCheck = null; //FIXME: update to whatever query you use to get the div you're checking
if (divToCheck.hasClass('tooltipstered')) {
  //TODO: update your title
}

You can check that it needs to be instantiated or simply enabled: 您可以检查是否需要实例化或只是启用它:

if (!$(id).hasClass("tooltipstered")) {
    $(id).tooltipster({
     position: 'top-left',
     contentAsHTML: 'true',
     theme: '.tooltipster-default',
     animation: 'grow'
    });
} else {
    $(id).tooltipster('enable');
}

Make sure that you checked it is instantiated before disabling it: 确保在禁用它之前检查了它是否已实例化:

if ($(id).hasClass("tooltipstered")) {
   $(id).tooltipster('disable');
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM