santa
santa

Reputation: 12512

Style column with jQuery

I need to style an entire column in a table. The column should correspond to the element with id="current" in the thead row.

<table>
<thead>
    <tr>
        <td></td>
        <td></td>
        <td><div id="current"></div></td>
        <td></td>
    </tr>
</thead>
<tbody>
    <tr>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
    </tr>
    <tr>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
    </tr>
</tbody>
</table>

Now, I can add a class to the correct column, I just need to figure out a way to tell the column count number.

var num = ???
$('td:nth-child(num)').addClass('selectedCol');

Upvotes: 0

Views: 131

Answers (1)

YogeshWaran
YogeshWaran

Reputation: 2281

try this

$("#current").closest('td').index()

Upvotes: 5

Related Questions