Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select all cells in nth column with jQuery

How do I select all cells in nth column of a normal html table. Ive tried this but its not working:

    $('table#foo tbody td:nth-child(3)').each(function (index) {
        $(this).addClass('hover');
    });

UPDATE: Heres a jsfiddle of the unworking code: http://jsfiddle.net/Claudius/D5KMq/

like image 407
Muleskinner Avatar asked Dec 04 '22 19:12

Muleskinner


1 Answers

There is no need to use each for this.

$('table#foo tbody td:nth-child(3)').addClass('hover');

Other than that, there's nothing wrong with your code. Problem must be somewhere else.

like image 84
fearofawhackplanet Avatar answered Dec 07 '22 22:12

fearofawhackplanet