SO - 19958908
by Arun P Johny
HTML
<table>
<thead>
<tr>
<th class="alignRight">Header1</th>
<th>Header2</th>
<th class="alignLeft">Header3</th>
</tr>
</thead>
<tbody>
<tr>
<td>Row1</td>
<td>Row1</td>
<td>Row1</td>
</tr>
<tr>
<td>Row2</td>
<td>Row2</td>
<td>Row2</td>
</tr>
<tr>
<td>Row3</td>
<td>Row3</td>
<td>Row3</td>
</tr>
</tbody>
</table>
CSS
.alignRight {
color: red;
}
.alignLeft {
color: green;
}
JavaScript
$('table thead th[class]').each(function (idx) {
$('table tbody td:nth-child(' + ($(this).index() + 1) + ')').addClass(this.className)
})