I was reading the http://docs.jquery.com/Tutorials:Getting_Started_with_jQuery. And got confused with use of this
in these 2 code segments.
$(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();
});
});
});
When do we need $(this)
and this
? And what is the difference between them? Thanks in advance.
$(this)
is needed in one part of this particular code whilethis
is needed in a different part..each()
function,this
refers to the actual element."