rjmcb
rjmcb

Reputation: 3745

How to check if selector has qtip?

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

For example

$('input').qtip("hasqtip");

Upvotes: 6

Views: 6282

Answers (3)

James879
James879

Reputation: 381

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>

Upvotes: 0

Baz1nga
Baz1nga

Reputation: 15579

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

Upvotes: 13

Starx
Starx

Reputation: 78971

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 
   }
});

Upvotes: 8

Related Questions