How to recognize an object - is it a jQuery object or not

I created a function that reports if there is a hold or jQuery object of a variable, is there any replacement for 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/

+4
source share
2 answers

Use instanceof :

 console.log(elm instanceof jQuery); 

or

 console.log(elm instanceof $); 

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

+11
source

Try an instance

 obj instanceof jQuery 
+3
source

Source: https://habr.com/ru/post/1386512/


All Articles