[Tooltipster Plugin]- Know if div already have tooltipster
Asked Answered
G

4

6

I'm using this plugin http://iamceege.github.io/tooltipster/.

It is possible know if a HTML already have the tooltipster initialized?

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. Like this:

$(this).tooltipster('destroy').attr("title", data.fields[i].value).tooltipster();
Goggler answered 26/8, 2015 at 14:39 Comment(0)
M
11

You can use the API:

Check if the element already has tooltipster:

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

$(...).tooltipster('content', myNewContent);
Moreen answered 26/8, 2015 at 14:43 Comment(2)
What if it has then been disabled ? It still has class ?Bellamy
@Bellamy Should be... This answer is about a plugin, and it has been development since then, and it's been 2 years. This might not be valid.Moreen
E
6

Accepted solution does not work on SVG elements with tooltipster v4.1.6. This is how I solved it:

if ($.tooltipster.instances($(node)).length == 0) {
    //it is NOT tooltipstered
}
else {
    //it is tooltipstered
}
Earpiercing answered 1/12, 2016 at 17:13 Comment(0)
P
0

Use .hasClass to check if it has the tooltipstered class

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
}
Pointsman answered 26/8, 2015 at 14:42 Comment(1)
Please edit with more information. Code-only and "try this" answers are discouraged, because they contain no searchable content, and don't explain why someone should "try this". We make an effort here to be a resource for knowledge.Strickman
B
0

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');
}
Bellamy answered 21/7, 2017 at 13:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.