Kind of large to paste here. My script and resulting HTML can be found at: http://jquery.pastebin.com/m3f98dd99
If you look towards the bottom you will see the following: .parents('td.embedded td.latest') .each(function(i) { $(this) .append(new_table) .addClass('mod' + i); }); I had to add the each because if I didn't my *new_table* was being appended 9 times. With the each it's only appended once, but the class is still added 9 times. Why?