(The only thing I can think of is that this is the element instead of a jQuery object in $("...").each(function)
-calls, as $(element)
is more often used then just the element. And that extremly minor thing is just about it.
Example of the above (simplified and I know that there are other much better ways to do this, I just couldn't think of a better example now):
// Make all divs that has foo=bar pink.
$("div").each(function(){
if($(this).attr("foo") == "bar"){
$(this).css("background", "pink");
}
});
each
is a function that takes a function as parameter, that function is called once for each matching element. In the function passed, this
refers to the actual browser DOM-element, but I find that you often will want to use some jQuery function on each element, thus having to use $(this)
. If this had been set to what $(this)
is, you'd get shorter code, and you could still access the DOM element object using this.get(0)
. Now I see the reason for things being as they are, namely that writing $(this)
instead of this, is hardly that cumbersome, and in case you can do what you want to do with the DOM element the way it is is faster than the way it could have been, and the other way wouldn't be faster in the case you want $(this)
.)