2013-01-08 73 views
1

我需要找到一個包含超鏈接文本值的TD(最低級別)。例如:jquery查找包含超鏈接的td

<td> 
    <a href....>Hours</a> 
</td> 

我想使用jQuery獲取元素並右對齊超鏈接文本。這是我正在使用(顯然不工作)。

$('td').filter(function(index) { return $(this).text().contains("Hours"); }).attr('style', "text-align:'right'"); 

回答

1

有一個專門選擇在jQuery的::contains

$('td:contains("Hours")').attr('style', "text-align:'right'"); 

由於我不知道你的問題(?「超鏈接」)的,如果你想獲得一個表,其鏈接href包含「小時」,你可以這樣做:

$('td a[href~="Hours"]').attr('style', "text-align:'right'"); 

編輯:格式化問題後,我認爲第二部分是無用的。