How can I clone a row in a table without cloning the values ​​of the input elements inside it?

I am trying to add a row to a table. I found that we can use the clone () method to duplicate an existing row. My table has two text inputs in two different elements <tr>. Cloning the last line also duplicates the values ​​in my text inputs, which I don't want? How can I clone a string without duplicating values?

Here is what I still have:

$("#table-1 tr:last").clone();
+5
source share
3 answers

Try the following:

var clone = $("#table-1 tr:last").clone().find('input').val('').end();

, .insertAfter("#table-1 tr:last") .

var clone = $("#table-1 tr:last").clone().find('input').val('').end().insertAfter("#table-1 tr:last");
+24

, :

$('#table-1 tr:last input').attr('value','');

:

$('#table-1 tr:last input').val('');
+1

, , , . true.

. ......

  var newRow = $("#table-of-items     tr:last").clone(true).find(':input').val('').end();

  $("#table-of-items").append(newRow);

- .

+1

All Articles