This is often used when jquery's each is used for loop traversal. To use the jquery method, the object must be a jquery object, the following describes how to judge a jquery object. When we use jquery's each for loop traversal, this is often used. Sometimes we don't know what this refers, because to use the jquery method, the object must be a jquery object.
You can also use typeof to determine the type of a javascript Object,
However, typeof can only determine the basic object (string, boolean, number, object) of js)
To determine whether an object is a jquery object, you can use obj instanceof jQuery.
For example:
The Code is as follows:
Var obj = $ ("p ");
If (obj instanceof jQuery ){
Alert ("This Is A jQuery object ");
} Else {
Alert ("this is another object ")
}
The Code is as follows:
$ (". OtherWeek"). each (function (){
Console.info (this instanceof jQuery); // false
Console.info ($ (this) instanceof jQuery); // true
})