Reputation: 627
I have a table with function "add new column". When it is pressed, a new column is added, but it has previous column values. How can I clean cloned input value?
My table looks like:
<tr>
<td><input style="width:80%" id="row_name2" type="text" name="option[0][]" value="" /></td>
</tr>
jquery:
var table = line.parentNode.parentNode;
jQuery.each( jQuery('tbody tr',table) , function(i, obj){
jQuery('td:eq('+(cols-2)+')',obj).after(
jQuery('td:eq('+(cols-2)+')',obj).clone()
);
});
Upvotes: 0
Views: 584
Reputation: 1268
If you are cloning something and you want to make sure the values are not part of the cloning, you want to have a process that is: find target
-> clone
-> clear vals
-> append
.
here's a simple (untested, trimmed from one I us) function for clearing the values in your tr
function clear_vals(tr){
tr.find('input').val('');
return tr;
}
Upvotes: 1
Reputation: 1399
$(Element).attr("name", "Your Name"); // is name of the column, not the displayed value.
Upvotes: 0