[Tooltipster Plugin] - Know if a div already has a tooltipster

I am using this plugin http://iamceege.imtqy.com/tooltipster/ .

Perhaps it is known that HTML already has an initialized tooltipster?

I want to know, because sometimes I need to change the tooltip text, and for this I need to destroy the tooltipster, change the attribute name of the HTML object and initialize again. Like this:

$(this).tooltipster('destroy').attr("title", data.fields[i].value).tooltipster();
+4
source share
4 answers

You can use the API:

Check if the item already has tooltipster:

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

$(...).tooltipster('content', myNewContent);
+7
source

SVG tooltipster v4.1.6. :

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

.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
}
0

You can verify that it should be created or just included:

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

Before disabling it, make sure you check it.

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

All Articles