My personal understanding of this and $ (this) _ jquery-js tutorial

Source: Internet
Author: User
This refers to a javascript Object and $ (this) is a jquery object. If you do not know this, you can read this article. The Code is as follows:


JQuery. prototype. test = function (){
This.css ("color", "#99"); // here this is a jquery object, not a dom object.
Alert (this [0]); // here this [0] refers to the dom Node object
}


The Code is as follows:


$ ("Body"). click (function (){
$ (This). test ();
Certificate (this).test().html (this. nodeName). hide (10000 );
})


When the click method is used on the page, it is equivalent to creating a new Jquery object and then calling its click method. The parameters in the method are a javascript function, this indicates a javascript Object. this is the syntax keyword of javascript itself. It points to a javascript Object. Therefore, you can use the method of the target javascript Object.

JQuery. prototype. test is equivalent to creating a test method for the query object. Therefore, this should be the jquery object.

This [0] can be used to convert a jquery object to a dom Node object.
Because this always points to the object that calls this method (function) (except the call and apply methods)

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.