Method _ jquery

Source: Internet
Author: User
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
})

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.