I have a table with 5 rows, My requirement is to add/delete table row dynamically..at the same time to handle the table row id dynamically.
Please find my table here:
<table>
<tbody>
<tr id='1'>
<td>Row 1</td>
</tr>
<tr id='2'>
<td>Row 2</td>
</tr>
<tr id='3'>
<td>Row 3</td>
</tr>
<tr id='4'>
<td>Row 4</td>
</tr>
<tr id='5'>
<td>Row 5</td>
</tr>
</tbody>
I am using jquery below code for deletion. For ex. I am deleting second row, then the row id 2 has been deleted and row id should be interchange dynamically.
Find my script here:
var index = $(this).closest('tr').index();
if (index > 0) {
$(this).closest('tr').remove();
}
Any help on this?
use nextAll
method to select all next element .. to change the id .it works effectively
$("tr").click(function () {
$(this).nextAll().each(function () {
var id = $(this).prop("id", function (index, idvalue) {
return idvalue - 1;
});
});
$(this).remove();
});
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments