Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know an object is jQuery object or not

Tags:

jquery

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/

like image 968
Rusi Nova Avatar asked Dec 06 '22 17:12

Rusi Nova


1 Answers

Use instanceof:

console.log(elm instanceof jQuery);

or:

console.log(elm instanceof $);

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

like image 86
karim79 Avatar answered Dec 10 '22 11:12

karim79