Rusi Nova
Rusi Nova

Reputation: 2665

How to know an object is jQuery object or not

I have created a function which tells whether a variable hold jQuery object or on is there any substitute of this. Below is my code

/*Is there any substitute of this function*/

function iSJqueryObj(elm)
{
    return elm && jQuery.isFunction(elm.html);
} 

http://jsfiddle.net/kE7Lp/3/

Upvotes: 4

Views: 4151

Answers (2)

mas-designs
mas-designs

Reputation: 7556

Try the instance of

obj instanceof jQuery

Upvotes: 3

karim79
karim79

Reputation: 342765

Use instanceof:

console.log(elm instanceof jQuery);

or:

console.log(elm instanceof $);

Demo: http://jsfiddle.net/karim79/8jUKX/

Upvotes: 12

Related Questions