The .change clone works for the first field, but not for the second. What can I add to my loop?
Thanks.
<table>
<tr>
<td><input type="text" id="txtA" name="txtA"></td>
<td><input type="text" id="txtB" name="txtB"></td>
</tr>
</table>
<script>
var i = 1;
$("#txtA").change(function() {
$("table tr:first").clone().find("input").each(function() {
$(this).val('').attr('id', function(_, id) { return id + i });
}).end().appendTo("table");
i++;
});
</script>
Change
.clone()to.clone(true)to also clone event handlers.JSFIDDLE DEMO
If you meant that you want the
changehandler to be bound to both inputs, then just add the ID of the second element to the selector: