Home >Web Front-end >JS Tutorial >Use jQuery wrapped methods or properties_jquery through $(this)

Use jQuery wrapped methods or properties_jquery through $(this)

WBOY
WBOYOriginal
2016-05-16 16:47:521076browse

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;
});
Statement:
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