Cloning a table row.
Hello I am new to jquery I have a problem with cloning a table row. It gets messed up if the method is called more than once. The information is added several times in a row. The html-code is merely used as markup, template information in this case. all content is added through jquery and it's been a delight developing with it up until this point! However, I cant seem to get past this issue that I'm having. If you could just glance at the code for a second or two, do you see any weirdness? [code] function LoadItems_Success(xml) { //use the markup row as template var $template = $("#content table.stuff > tbody > tr:first").clone(true); var tbody = $("tbody"); //remove all items before adding things to it. //this is required since its going to be invoked more than once. $("#content table.stuff > tbody").empty(); //populate table with data from server $(xml).find("Item").each(function() { var $row = $template; var $item = $(this); var $id = $item.find("id"); var $date = $item.find("date"); var $sum = $item.find("sum"); if ($date.text().length >= 10) $row.find("td.date").text($date.text().substring(0, 10)); else $row.find("td.date").text($date.text()); $row.find("td.sum").text( Math.round($sum.text() *1)/1 ); $row.find("td.action").attr("data-id", $id.text()); $row.appendTo(tbody); }); $("#content table.stuff").append(tbody); }