1.JQuery the difference between this and $ (this)
I believe many people who have just come into contact with jquery will have a vague distinction between $ (this) and this one, so what is the difference between the two?
First look at the $ () symbol in jquery, which in fact is the equivalent of jquery () in jquery, which is the $ (this) =jquery (), which means that you can return a jquery object. Well, when you are in the Web page alert ($ (' #id ')), a [object object] will pop up, which is the jquery object.
So, let's go back to the $ (this), what's this? Suppose we have the following code:
$ ("#desktop a img"). each (function (index) {
Alert ($ (this));
alert (this);
}
Well, this time you can see:
Alert ($ (this)); The result of the popup is [object Object]
alert (this); The bounce is [object Htmlimageelement]
That is, the latter returns an HTML object (in this case an IMG object that iterates through the HTML, so it is htmlimageelement).
Many people often this.attr (' src ') when using jquery. This will cause an error "object does not support this property or method", which is why? In fact, see the above example, we know where the wrong: very simple, this is the HTML object, then the HTML object can have the Val () method, so in use, we can not directly use this to directly invoke the method or property of jquery.
2. Get the method for the (this) child node object: Find (Element)
Understand the difference between $ (this) and this, and then take a look at this example: (Assuming that my page contains an img in a tag and contains the SRC attribute), when I traverse, I want to fetch the address of the SRC in the IMG under the $ (this)
$ ("#desktop a"). each (function (index) {
var imgurl=$ (this). FIND (' img '). attr (' src ');
alert (Imgurl);
}
where. Find (Element) is a DOM element that returns a matching element so that it can fetch the desired SRC address.
Source: http://www.cnblogs.com/hannover/p/4109779.html
The difference between JQuery this and $ (this) and how to get the $ (this) child element object