What is the following two code to see on jquery's website, when to use $ (this), and when to use this?
$ (document). Ready (function () { $ ("#orderedlist li:last"). Hover (function () { $ (this). AddClass ("green"); , function () { $ (this). Removeclass ("green"); # $ (this) });});
$ (document). Ready (The function () {//Use the-to- reset several forms at once $ ("#reset"). Click (function () { $ (" Form "). each (function () { this.reset (); # this});}) ;
If you want to use the properties or methods of the HTML element itself to use this, if you want to use jquery wrapped method or property to use $ (this), generally have the following relationship
$ (this) [0]==this;
The code above is to use this where the Reset method is to invoke form form, and this method jquery does not have wrapper support, so only this.reset (), can also use $ (this) [0].reset ();
Meaning this is an HTML element object
$ (this) becomes a jquery object
This is a keyword in JavaScript.
$ (this) can be thought of as wrapping the this in JavaScript, and wrapping the $ (this) will inherit the jquery method.
The essence is the translation of JavaScript and jquery objects
$ (' a '). Click (function () { //) Here this points to the currently clicked Dom node, which is a. You can call DOM methods, such as This.getattribute, This.tagname ... The $ (this) here represents a wrapped jquery object that has some of the methods of jquery, such as $ (this). AddClass (), $ (this). Hide () ...});
$ (this) is a jquery object that can invoke the method of jquery, such as Click (), KeyUp ().
This, then, is an HTML element object that can invoke element attributes, such as This.id,this.value.
For example, if you have made this and $ (this) point to the input object, to get the value of input, you can this.value, but $ (this) will be $ (this). Val ().
What is the difference between $ (this) and this in jquery?