I want to add progressive id to a series of elements on an unordered HTML list. I used the jQuery .each()
method to get each <li>
of the List and append a <span>
inside each <li>
. Then I added the ID attribute with index of each() as number.
$('#menu li ul li').each(function(i, e){
$(this).append('<span class=arr></span>');
$(.arr).attr(id, id_ + i);
});
But I get id_3
for all elements. Why? What did I do wrong?
Thanks for any help!