I'm learning jQuery but I still don't fully undestand how it works. Suppose I have an unordered list like this:
<ul>
<li name="one">xxx</li>
<li name="two">xxx</li>
<li name="three">xxx</li>
</ul>
and I want to subsitute every line's text value with its name. Can you explain me why this works:
$('li').each(function() {
$(this).text($(this).attr('name'));
});
while this one does not?
$('li').text($(this).attr('name'));