开发者

Select table cells w/ jQuery

开发者 https://www.devze.com 2023-04-01 14:15 出处:网络
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...

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</t开发者_如何学运维d>
    <td>select</td>
    ...
</tr>
</table>


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


$allTableCellsButFirst = $('table tr td').not('tr:first-child td:first-child');

Should do the trick for you.

Working Example via jsFiddle


$('table tr td:first-child').siblings();


You could add a class to your TD's:

$('#someTable .tableCell').each(function()
{
    alert($(this).html());
});
0

精彩评论

暂无评论...
验证码 换一张
取 消