2013-07-23 51 views
0

我有這樣的代碼:我將如何選擇具有相同名稱的所有div類,除了當前div中的jquery/javascript?

<div class="pvh_wrap"> 

<div class="pvh_item"> 
<div class="pvh_overlay"></div> 
<div class="pvh_title">Lorem ipsum dolor sit amet</div><!-- end .pvh_title --> 
<div class="pvh_button"><strong>Vote</strong></div><!-- end .pvh_button --> 
</div><!-- end .pvh_item --> 

<div class="pvh_item"> 
<div class="pvh_overlay"></div> 
<div class="pvh_title">Lorem ipsum dolor sit amet</div><!-- end .pvh_title --> 
<div class="pvh_button"><strong>Vote</strong></div><!-- end .pvh_button --> 
</div><!-- end .pvh_item --> 

<div class="pvh_item"> 
<div class="pvh_overlay"></div> 
<div class="pvh_title">Lorem ipsum dolor sit amet</div><!-- end .pvh_title --> 
<div class="pvh_button"><strong>Vote</strong></div><!-- end .pvh_button --> 
</div><!-- end .pvh_item --> 

<div class="pvh_item"> 
<div class="pvh_overlay"></div> 
<div class="pvh_title">Lorem ipsum dolor sit amet</div><!-- end .pvh_title --> 
<div class="pvh_button"><strong>Vote</strong></div><!-- end .pvh_button --> 
</div><!-- end .pvh_item --> 

<div class="pvh_item"> 
<div class="pvh_overlay"></div> 
<div class="pvh_title">Lorem ipsum dolor sit amet</div><!-- end .pvh_title --> 
<div class="pvh_button"><strong>Vote</strong></div><!-- end .pvh_button --> 
</div><!-- end .pvh_item --> 

</div><!-- end .pvh_wrap --> 

是在點擊pvh_button時,顯示我想要做的pvh_overlay的div除了一個在當前DIV。當前div將是pvh_button被點擊進入的pvh_item類。我有這個目前爲止打開了所有pvh_overlay的設置來顯示:inline,但我希望除了當前打開的所有pvh_button都打開。我將如何做到這一點?

<script> 
$('.pvh_button').click(function(event) { 
    $('.pvh_overlay').css('display', 'inline');  
}); 
</script> 

謝謝。

回答

3
$('.pvh_button').click(function(event) { 
    var $currentContainerOverlay = $(this).parent().children('.pvh_overlay'); 
    $('.pvh_overlay').not($currentContainerOverlay).css('display', 'inline');  
}); 
+0

太棒了,謝謝! – jdc987

+0

爲什麼這不被接受爲答案@jdc?任何原因? – Learner

+0

Stackoverflow不會讓我接受它11分鐘,現在是。 – jdc987

0

可能不太解析需要具有兄弟姐妹()方法。如果您正在解析巨大的HTML結構,速度會更快。

$('.pvh_button').click(function(event) { 
    $('.pvh_overlay').not($(this).siblings('.pvh_overlay')).css({'display':'inline' });  
}); 
相關問題