Possible Duplicate:
jQuery $(this) vs this
In jquery sometimes I find that within a function I have to use $(this) because this won’t work:
var listItems = $('li');
listItems.each(function(index) {
$(this).css({
})
})
Any ideas as to the reason why?
$()is thejQuery constructorfunctionthisis a reference to theDOM element of invocationSo basically, you’re turning a
DOM referenceinto ajQuery objectIn your example, you could also use
..since
.each()will pass both, index + element in its callback.