Add a row to a table with jQuery but its value is not needed

Possible duplicate:
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. my table contains two text fields in two different tr.cloning, the last row also duplicates the values ​​in my text field that I don't need? Any ideas ???

my code

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

maybe something like this

 $("#table-1 tr:last").clone().find('input[type=text]').val('');
+1
source

If you want to add a line with inputs but not values, you can do something like what you have and just clear the values:

var row = $("#table-1 tr:last").clone();
row.find( 'input' ).each( function(){
    $( this ).val( '' )
});
row.appendTo( "#table-1" )
+1
source

:

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

// then add the row at the end of the table
$("#table-1").append(row);
0

All Articles