Possible Duplicate:
How to use jQuery to add a new row to a table, and assgin an incrementing id to it
I’ve got some table rows as per below:
<td><input id="RS_Staff_Title1" name="RS_Staff_Title1" style="width:100%;"></td>
<td><input id="RS_No_WD_Staff1" name="RS_No_WD_Staff1" style="width:100%;"></td>
<td><input id="RS_No_Weekdays1" name="RS_No_Weekdays1" style="width:100%;"></td>
<td><input id="RS_No_WE_Staff1" name="RS_No_WE_Staff1" style="width:100%;"></td>
<td><input id="RS_No_WE_Days1" name="RS_No_WE_Days1" style="width:100%;"></td>
<td><img class="remove_row" src="assets/images/delete-icon.png"></td>
I’ve then got a button which takes the last table row and clones it to the one below, therefore adding a new line using this Jquery”
$("#add_row").click(function() {
$('#staff tbody>tr:last').clone(true).insertAfter('#staff tbody>tr:last');
return false;
});
What I need to happen is for the RS_Staff_Title1 to become RS_Staff_Title2, RS_Staff_Title3 and so on – the same would happen for the other columns as well.
How can I go about acheiving this?
One possible solution:
DEMO: http://jsfiddle.net/GHTN7/