I have following jQuery .each loop:
$('.table-data tbody tr td').each( function(index) {
$('.table-data tbody tr td' + ':nth-child(' + index + ')' ).addClass( 'nth-' + index );
});
The problem is that it will work, but the last element of the .table-data tbody tr td' will not get a class. Why?
Is this because index is 0 based? How to make it loop for index + 1 time?
You don’t need to drill down to the current element using the index, it’s easier than that!
To renumber the TD elements within each row, try this.
OR, if you want to be a bit cleverer, this…
See this in action: http://jsbin.com/usaqix