The difference between this and $ (this) in jquery

Source: Internet
Author: User

The difference between this and $ (this) in jquery initially thought this and $ (this) to be a die carved out. But when I read, and coding, it's not always the same, here's the difference between this and $ (this).             The difference between this and $ (this) in Ad:jquery $ ("#textbox"). Hover (function () {this.title = "Test";             }, Fucntion () {this.title = "OK"; }       ); Here this is actually an HTML element (textbox), TextBox has the Text property, so it is absolutely no problem to write. But if you change this to $ (this) it is not the case, error--reported.    This is the difference between this and $ (this).              Error Code: $ ("#textbox"). Hover (function () {$ (this). title = "Test";              }, Function () {$ (this). title = "OK"; }       ); 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 way to do this is as follows: The correct code: $ ("#textbox"). Hover (function () {$ (t             His). attr (' title ', ' Test ');             }, Function () {$ (this). attr (' title ', ' OK '); }       ); The advantage of using jquery is that it packs a variety of browser versions on DOM objects, so use $ (this) uniformly instead of this should be a comparisonA good choice. The difference between this and $ (this) in jquery is here

 

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.