tags:

views:

232

answers:

3

I would like to select all cells of the first column of a table. Can anyone please tell me the coe.

Tried this..

$('.sortable tr:nth-child(1)');    // getting entire row.
A: 
$('.sortable td:first-child'); 
kgiannakakis
mmm.... $('.sortable td:first-child'); would take all first td in class .sortable....
Reigel
ahhh good one... I missed the problem... ;)
Reigel
This will only work for `td` cells, but not for `th` cells.
stakx
In my opinion, it is a good thing that th cells are not selected, as these are usually treated differently. Also, the OP mentioned nothing about th cells.
kgiannakakis
thanks.. needed this
atif089
A: 
$('.sortable tr td:first').each(function(){ 
     alert($(this).text());
}); 
Reigel
I believe this will only select the very first cell of the table. Replacing `:first` with `:first-child` should give the expected result.
stakx
+1  A: 

This (fairly verbose) selector should work:

$(".sortable tr > :nth-child(1)")

If you want another column, simply change the index to nth-child to something other than 1.

This will select both td (data) and th (header) cells, btw.

stakx