I have a problem where the :eq()
does not accept the counter, n
, to insert values to a new column to the table in the HTML.
$(document).ready(function() {
var $tablerow = $('table.table').find('tr');
count = 0;
$tablerow.each(function(index, value){
count += 1;
var $listitem = $(this);
n = parseInt($listitem.index());
var $newRow = $("<td>" + n + "</td>");
$("table.table tr:eq(n)").append($newRow);
});
});
HTML
<table class="table">
<tr><td>First row</td></tr>
<tr><td>second row</td></tr>
<tr><td>third row</td></tr>
<tr><td>fourth row</td></tr>
<tr><td>fifth row</td></tr>
<tr><td>sixth row</td></tr>
<tr><td>seventh row</td></tr>
<tr><td>eighth row</td></tr>
</table>