I am having trouble removing the last DD and DT tags from a definition list when prepending new content using .each. My goal is to remove a set of DD and DT tags with each iteration (as new DD and DT tags are prepended). The following is example code I am using:

1 Answer
1

Only one element is being removed from the list because the each loop is going through all the items in json.shouts before the first slideUp call finishes (ie the loop is too fast or slideUp is too slow). This means that each time this executes:

the original last item in the list is always being found, so you're actually calling slideUp on the same element json.shouts.length number of times. You need to get all the original items in the list before the each loop starts and count backwards to remove one for each new item added.

Thanks! This works. The animation looks a little strange. But I understand the concept now. I'm just a little confused on what this syntax actually means: "existingDts.length - 1 - id"
–
Andy ShinnMar 31 '11 at 16:15

existingDts.length minus one minus id. This is done to get the index of the item in the array (existingDts and existingDds) that you wish to remove. length - 1 gets you the index of the last item in an array. id will be 0, 1, 2, 3... going through the each loop
–
canderMar 31 '11 at 16:49

Ah, I understand now. I used console.log() to show me information through the iteration to help me understand. Thanks again!
–
Andy ShinnMar 31 '11 at 17:02