The following jQuery is extremely slow (~7 sec). I’m clearly doing it the wrong way!
I’m trying to copy the contents of column col to column 0 in an HTML table
so if col is 2, then I need to copy column 2 to column 0.
for (var i=0;i<31;i++)
$('.grid tr:nth-child(' + i + ') td:first-child').text(
$('.grid tr:nth-child(' + i + ') td:nth-child(' + col + ')').text()
);
HTML:
<table>
<tr><td>A</td><td>D</td><td>G</td></tr>
<tr><td>B</td><td>E</td><td>H</td></tr>
<tr><td>C</td><td>F</td><td>I</td></tr>
<!-- etc. -->
</table>
You don’t need to select each table cell individually. You can select the source column and destination columns and iterate over them: