How to check if selector has qtip?
Asked Answered
C

3

6

How can I check if an element is instantiated with a qtip plugin?

For example

$('input').qtip("hasqtip");
Catgut answered 25/3, 2012 at 6:19 Comment(2)
What vertion of qtip? 1 or 2?Darra
I used version 1 of qtipCatgut
K
8

An very easy way would be to apply the plugin using a class selector like, in anchors

$("a.qtip").qtip(); //Apply qtip, to only those links with qtip class on them

Then, to check if a link has qtip on them, check their class

$('a').click(function() { //whenever a link is cliked
   if($(this).hasClass('qtip')) { //check if it has qtip class on them
     //if it has

     //SCREAM: yes i found a qtip :D 
   }
});
Kweilin answered 25/3, 2012 at 6:30 Comment(5)
Hmmm, just to test I tried it in jsfiddle but aint working check it out here: jsfiddle.net/dqkzV/9 ; but good reply! :) cheersThereabout
@Tats_innit, You didn't understood my point. See this fiddleKweilin
@Thereabout see my answer.. I used your jsfiddle.. thanks.. :DMarried
Yep, indeed! No complains! Perfect bruv! :) I did the same lol @Married :DThereabout
@Kweilin +1 to you as well mate!Thereabout
M
13

The authors suggested way to check for existence of qtip on an element is to use the following method:

if( 'object' === typeof $(elem).data('qtip') )

Demo

Married answered 25/3, 2012 at 6:42 Comment(2)
yes indeed works for this one check here: (working version reside here) jsfiddle.net/dqkzV/13 just sharing bruv! cheers!Thereabout
Is there a way to set typeof value back to 'undefined' ??Coliseum
K
8

An very easy way would be to apply the plugin using a class selector like, in anchors

$("a.qtip").qtip(); //Apply qtip, to only those links with qtip class on them

Then, to check if a link has qtip on them, check their class

$('a').click(function() { //whenever a link is cliked
   if($(this).hasClass('qtip')) { //check if it has qtip class on them
     //if it has

     //SCREAM: yes i found a qtip :D 
   }
});
Kweilin answered 25/3, 2012 at 6:30 Comment(5)
Hmmm, just to test I tried it in jsfiddle but aint working check it out here: jsfiddle.net/dqkzV/9 ; but good reply! :) cheersThereabout
@Tats_innit, You didn't understood my point. See this fiddleKweilin
@Thereabout see my answer.. I used your jsfiddle.. thanks.. :DMarried
Yep, indeed! No complains! Perfect bruv! :) I did the same lol @Married :DThereabout
@Kweilin +1 to you as well mate!Thereabout
M
0

Another way to do it

if($("#mybtn").attr("data-hasqtip")) {
$("#mybtn").qtip().destroy();
}

A qtip2 element will have an attribute data-hasqtip. If never instantiated or destroyed the attribute will be missing

e.g.

<button id="mybtn" class="infobtn" style="float: left; display: block;" data-hasqtip="2">
    <i class="fa fa-info-circle fa-lg"></i>
</button>
Magnification answered 8/2, 2015 at 5:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.