This and $ (this)

Source: Internet
Author: User

At first thought this and $ (this) is a die carved out. But when I read, and coding, it's not the same thing.

Here this is actually an HTML element (textbox), TextBox has the Text property, so it is absolutely no problem to write.

$ ("#textbox"). Hover (         function() {              this. title = "Test";         },         fucntion () {             this. title = "OK";         }   );   


But if you change this to $ (this) it is not the case, error--reported.

Error Code:  $ ("#textbox"). Hover (         function() {            $ (this). title = "Test";         },         function() {            $ (this). title = "OK";         }  );
View Code

The $ (this) here is a jquery object, and the jquery object does not have the title property, so it is wrong to write this.

jquery has the attr () method to get/set the properties of Dom objects, so the correct wording should be:

the correct code:  $ ("#textbox"). Hover (        function() {           $ (this). attr (' title ', ' Test ');        },        function() {           $ (this). attr (' Title ', ' OK ');        }  );  
View Code

This and $ (this)

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.