I am reading a jQuery book and sometimes I see the example like:
$('img[alt]').each(function(){
$(this).replaceWith('<span>' + $(this).attr('alt')+ '</span>')
}
and sometimes I see examples like:
$('*').attr('title', function(index, value) {
return value + 'I am element ' + index + ' and my name is ' + this.id);
});
so see sometimes it is $(this)
and sometimes it is just this
What's the difference? How do I know which one to use and when?