2012-05-24 24 views
5

我經常發現自己做的事情是這樣操作的表時: -

$($('table tr').children()[2]).html(); 

當我希望第三列中的單元格作爲jQuery包裝集合時。使用[n]選擇節點,然後傳遞給$()以獲得jQuery包裝集。

是否有一個更可讀的方式來做到這一點?

回答

7

使用.eq()方法

$('table tr').children().eq(2).html(); 

,你可以選擇使用的:eq selector

$('table tr > :eq(2)').html(); 
+0

好極了,我知道會有辦法!非常感謝你! – rgvcorley