Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How To find Out if Element is Wrapped by jQuery?

How can i find out if an Object is Wrapped by jQuery.

var obj = $('div');

if(obj is a jQuery wrapped object)
{
   then do something
}

I am quite new in the Javascript World.

Thanks in advance.

like image 989
rudimenter Avatar asked Aug 13 '09 09:08

rudimenter


2 Answers

Here you go:

var isJQuery = obj instanceof jQuery;  // or obj instanceof $;
like image 116
karim79 Avatar answered Sep 18 '22 13:09

karim79


if (obj.jquery) {
    /* Do something */
}

That's the simplest way. Checking the object's constructor is another option but note that it won't work across global contexts (e.g. between a parent page and a frame).

like image 22
James Avatar answered Sep 20 '22 13:09

James