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

Personal understanding of this and $(this)_jquery

WBOY
Release: 2016-05-16 17:23:08
Original
1221 people have browsed it
Copy code The code is as follows:

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

Copy code The code is as follows:

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

When using the click method on the page, it is equivalent to creating a new Jquery object and then calling its click method. The parameter in the method is a javascript function, and this inside refers to JavaScript object, this is the syntax keyword of JavaScript itself. It points to a JavaScript object, so you can use the method

owned by the pointed target JavaScript object. And jQuery.prototype.test is equivalent to the query object. Create a new test method, so the this inside should be the jquery object

. Through this[0], the jquery object can be converted into a dom node object
because this always points to the calling method (function ) of the object (except call and apply methods)
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!