Method to determine whether an object is a jquery object

  • 2020-03-30 02:20:09
  • OfStack

This is often used when we loop through each in jquery, and sometimes we don't know what this means, because to use jquery's method, the object must be a jquery object.

Also to determine what typeof object a javascript object is, you can use typeof,
But the basis of the typeof can only judge the js object (string, Boolean, number, object)

Obj instanceof jquery can be used to determine whether an object is a jquery object

Such as:
 
var obj = $("div"); 
if(obj instanceof jQuery){ 
alert(" This is a jQuery object "); 
}else{ 
alert(" This is another object ") 
} 

 
$(".otherWeek").each(function(){ 
console.info(this instanceof jQuery); //false 
console.info($(this) instanceof jQuery); //true 
}) 

Related articles: