jQuery选择列
我想选择表格第一列的所有单元格。 任何人都可以告诉我代码。
试过这个..
$('.sortable tr:nth-child(1)'); // getting entire row.
$('.sortable td:first-child');
这个(相当详细)选择器应该工作:
$(".sortable tr > :nth-child(1)")
如果您想要另一列,只需将索引更改为nth-child
,而不是1
。
这将选择td
(数据)和th
(标题)单元格,btw。
$(".sortable tr > :nth-child(1)") .css("background-color", "yellow");
A B C 1 2 3 10 20 30 100 200 300
$('.sortable tr td:first').each(function(){ alert($(this).text()); });