I want to build a list. No problem.
for (i = 0; i < 7; i++) {
$('#domid').append(variable.clone());
}
How do I get the LAST item in the list (in this case i.7) and add a class to it?
for (i = 0; i < 7; i++) {
$('#domid').append(variable.clone());
if (i===7) {
$('.domclass').addClass('last');
};
}
But that won’t work. That just makes all of the .todo items have the class when the counter get’s to 7.
Any suggestions on how to find this?
Thanks!
Or, if you’d like to do it in the loop (so, as the commenter pointed out, you don’t have to traverse the DOM to get to the element again):