Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery and Table, grab every cell in the NTH column

Tags:

jquery

Lets say I have your basic table layout (like below). How to I grab every NTH cell? I basically want to add a css class to the cells in column N.

So if I wanted all cells in column 2, I want to have a jQuery obj that contain the following cells that are marked:

<table>
    <tr class="trow">
        <td></td>
        <td></td> <!-- included -->
        <td></td>
    </tr>
    <tr class="trow">
        <td></td>
        <td></td> <!-- included -->
        <td></td>
    </tr>
    <tr class="trow">
        <td></td>
        <td></td> <!-- included -->
        <td></td>
    </tr>
</table>
like image 788
Jon Erickson Avatar asked Aug 18 '09 22:08

Jon Erickson


1 Answers

Try the jQuery nth Cell selector... Must be there!

$("table tr td:nth-child(n)").addClass("MyGreatClass");
like image 192
RSolberg Avatar answered Nov 07 '22 15:11

RSolberg