-1

How do I select all but the first TDs? I don't know how many columns there could be in the table, so I can't really use :nth-child(2) etc...

<table>
<tr>
    <td>do not select</td>
    <td>select</td>
    <td>select</td>
    <td>select</td>
    ...
</tr>
</table>
santa
  • 11,716
  • 43
  • 149
  • 239

4 Answers4

4

Try this using :gt(0) which select all elements at an index greater than index within the matched set.

$("table td:gt(0)");

Working demo

ShankarSangoli
  • 68,720
  • 11
  • 89
  • 123
3
$allTableCellsButFirst = $('table tr td').not('tr:first-child td:first-child');

Should do the trick for you.

Working Example via jsFiddle

Madara's Ghost
  • 165,920
  • 50
  • 255
  • 304
1
$('table tr td:first-child').siblings();
Marc B
  • 348,685
  • 41
  • 398
  • 480
0

You could add a class to your TD's:

$('#someTable .tableCell').each(function()
{
    alert($(this).html());
});
Brian
  • 7,963
  • 2
  • 23
  • 32