Possible Duplicate:
jQuery $(this) vs this
What is the difference between "this" and "$(this)"?
How do I know which one to use?
Related, I think:
With each, you have the optional parameters. How is the "i" different than "this" (or "$(this)")?
$('img').each(function(i) { ....code }
vs.
$('img').each(function() { ....code }
the this
object doesn't change. It is the owner of the function. It is, in most cases like this, simply a node and you can reference all of its properties like this.className
. (think of it as you would a node or whatnot that you get with document.getElementById
). It is just the "owner" of the function.
Therefore, you are just passing the this
object to jQuery's $()
.
Conclusion: If you want to use jQuery functions for the current node, use $(this)
. But if you want to access the objects own properties (e.g. .name
, className
, .id
), use simply this
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With