What is the difference between $(this)and thisin jQuery? Here are two different uses:
$(this)
this
$(document).ready(function() { $("#orderedlist").find("li").each(function(i) { $(this).append( " BAM! " + i ); }); }); $(document).ready(function() { // use this to reset several forms at once $("#reset").click(function() { $("form").each(function() { this.reset(); }); }); });
The variable "this" refers (in cases like the event handlers you provided) to the DOM element. So $ (this) is a jQuery object containing only one DOM element.
You should use the usual "this" when you need to use your own DOM APIs, and $ (this) when you need jQuery help. Your second example is a good illustration; another may be when you just need the "id" or "name" of the element.
, this dom, . $(this) jquery dom.
EDIT: , DOM jquery, , dom. this , document.getElementById(id)
document.getElementById(id)
$(this)is a jquery object, and thisis a native dom object