2013-05-03 67 views
-1

我有一組具有兩個標籤的TD。我想找一種方法找到其中一個標籤並隱藏其他標籤。找到一個標籤,並在其旁邊隱藏另一個標籤

這裏是我到目前爲止,

if($('td').find('.mark')) { 
     $('.warning').hide(); 
    } 

但我只希望它隱藏。警告在那個特定的TD,而不是所有.warning語句標籤。

這裏的小提琴,http://jsfiddle.net/amQ4G/2/

謝謝

UPDATE

我的道歉,我搞砸了對我的工作的HTML,這裏的HTML版本,我想它喜歡它http://jsfiddle.net/amQ4G/9/

這些標記位於不同的TD中,一個存在於一個TD內,另一個隱藏在TD旁邊的TD中。

+0

我不認爲你的jsFiddle是你想要做的一個很好的例子。 – j08691 2013-05-03 18:56:02

+1

'.find()'不返回真/假。請檢查'.length'。 – 2013-05-03 19:00:12

+0

@SalmanA感謝您提供的信息,對於未來的項目肯定會記住這一點。 – Richard 2013-05-03 19:12:08

回答

1

可以簡單地寫成如下以及

$('tr').has('.mark').find('.warning').hide() 

根據問題的更新更新

+0

工作就像一個魅力!謝謝! – Richard 2013-05-03 19:09:13

0

這裏是(用於編輯的問題),一個解決辦法:

$('.mark'). //select all elements with the class 'mark' 
parent(). //select the parent of all of those elements 
parent(). //my grandpapy selector 
find('.warning'). //find the children with the class 'warning' 
hide(); //hide yo kids, hide yo wife, and hide yo husband cause they jQuerying everybody 

http://jsfiddle.net/amQ4G/12/

+2

+1讓我大笑,它的作品。 – tymeJV 2013-05-03 19:03:16

+0

這是隱藏所有警告類,我只是想要它隱藏沒有標記類 – Richard 2013-05-03 19:05:33

+0

請參閱編輯&小提琴 – 2013-05-03 19:08:03

2

您可以使用前面的兄弟選擇:

$('td .mark + .warning').hide() 

或者更冗長:

$('td').find('.mark').next('.warning').hide() 
0

ü可以嘗試這樣

$(document).ready(function(){ 
    if($('td').find('.mark')) { 
     $('.mark').parent('td').find('.warning').hide(); 
    } 
}); 

更新撥弄鏈接http://jsfiddle.net/amQ4G/6/

相關問題