Home > Web Front-end > JS Tutorial > body text

Use jQuery wrapped methods or properties_jquery through $(this)

WBOY
Release: 2016-05-16 16:47:52
Original
1012 people have browsed it

If you want to use the attributes or methods of the html element itself, you need to use this. If you want to use the methods or attributes wrapped by jQuery, you need $(this). Generally, there is the following relationship.

Copy code The code is as follows:

$(this)[0] == this;

top The code in this article is to use this to call the reset method of the form. However, jQuery does not have packaging support for this method, so this.reset() is available. You can also use $(this)[0].reset( );

Regarding when to use both? You can see the following example:
Copy code The code is as follows:

Copy code The code is as follows:

$('a').click(function( ){
this.innerHTM==$(this).html()=='jQuery';//The three are the same.
this.getAttribute('href')==this.href== $(this).attr('href')//The three are the same;
this.getAttribute('target')==this.target==$(this).attr('target')// The three are the same;
this.getAttribute('data-id')==$(this).attr('data-id')//The two are the same;
});
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!