2011-09-15 30 views
2

如何獲得具有屬性的衣櫃?gettr()與attr()

$('tr[data-order]:closest', $(this)).css({background:'red'}); 

我需要得到家長tr與attriute data-order

+1

這? '$(this).closest('tr [data-order]')'。順便說一下,你是說有多個TR祖先(如在嵌套表中)? –

回答

5
$('theStartingObject').closest('tr[data-order]'); 
+0

這與OP發佈的內容有何不同? – Jon

+0

@Jon OP的代碼搜索後代,這段代碼搜索祖先... –

+0

@Jon好吧,OP似乎試圖使用稱爲'最接近'的僞選擇器,據我所知,它不存在。這個答案使用了jQuery的'nearest()'函數,它的確如此。或者我錯過了什麼? –