-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
  • 12,234
  • 49
  • 155
  • 255

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
  • 69,612
  • 13
  • 93
  • 124
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
  • 172,118
  • 50
  • 264
  • 308
1
$('table tr td:first-child').siblings();
Marc B
  • 356,200
  • 43
  • 426
  • 500
0

You could add a class to your TD's:

$('#someTable .tableCell').each(function()
{
    alert($(this).html());
});
Brian
  • 8,418
  • 2
  • 25
  • 32