Home > Web Front-end > JS Tutorial > Personal understanding of this and $(this)_jquery

Personal understanding of this and $(this)_jquery

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 17:23:08
Original
1283 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
Latest Issues
Why is this ID written like this?
From 1970-01-01 08:00:00
0
0
0
Small question about $this
From 1970-01-01 08:00:00
0
0
0
What's the use of this?
From 1970-01-01 08:00:00
0
0
0
This file demo.mp4
From 1970-01-01 08:00:00
0
0
0
javascript - es6中this
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template