i want to calculate the table rows, then assign to each tr in table id number based on the number of row,
i did the calculation like this var currentIndex = $('table tbody tr').length
and i got the number of rows, then when i try to loop the rows, it change the id in all the rows with the same id, for example 1, i need to make it , for row number 1 id=1, row 2 = id=2 ..etc
` function generateId() {
for (i = 0; i < $('table tbody tr').length; i++) {
console.log('Hello World', + i -1);
$('table tbody tr td :input').attr('id', + i).attr('name', + i).prop('class', 'form-control form-control-sm form-control-solid formInput-' + i);
//$('table tbody tr td :input').attr('name', + i);
//$('#table tbody tr td :input').attr('class', 'form-control form-control-sm form-control-solid' + i);
}
`
any ideas ??!!
2
Answers
You can do it like this:
Also it’s not recommended that id is a number.
Demo
To give id to each row based on number of rows. You can do it like this:-