Frank Leal Frank Leal - 1 year ago 87
jQuery Question

jQuery can't clone() and appendTo() with html before

People am here because am having this code that actually doesnt work, it bassically duplicate a row and make a new row for a new entry. Am ussing



But if you remove the last part of the html it will work, it seems like if there is a new tag it goes worng syntax, please could someone help me with this trouble?.

<td>Hello world!</td>


Answer Source

There are few issues in your fiddle

1: the row element selected to be cloned is wrong.

2: parent element should be table but that is wrongly selected.

You can use the below modified code for cloning and appending the row.

 $("#clone").click(function() {
    var parent = $("#data");
    var tr = $("#data tr:last");
    var e = tr.clone().appendTo(parent);
    $(e).find("[type=text],[type=hidden]").each(function() {

updated Fiddle :

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download