Let’s say I have a table :
<table id="myTable">
<thead>
<th> Col1 </th>
<th> Col2 </th>
</thead>
<tbody>
<tr><td>1</td><td>2</td></tr>
<tr><td>1</td><td>2</td></tr>
</tbody>
</table>
And I want to add the values in column named Col2, which is 4. I don’t want to add the values by the position of the column, which is answered here, since the position of the column is variable.
A little explanation
$('td:eq('+ index +')', this).text()get the text of corresponding td$.trim( $('td:eq('+ index +')', this).text() )removing spaces from textparseInt( $.trim( $('td:eq('+ index +')', this).text() ), 10)converts the value of integetsum += parseInt( $.trim( $('td:eq('+ index +')', this).text() ), 10);performing the sum.DEMO