2011-11-17 91 views
6

可能重複:
nearest ancestor node in jQueryjQuery的獲取最近的父

HTML:

<div class="post"> 
    <h2><a href="#" title="">Pellentesque</a></h2> 
    <p><a href="#" title="" class="more">More</a></p> 
</div> 

jQuery的

$('.more').bind("hover", function(){ 
    $(this).parent('.post').hide() ;      
}); 

懸停(更多)我想隱藏的職位,但它什麼都不做,如果我用父母( )而不是將其刪除所有

任何幫助讚賞

+0

最接近的是同樣的事情,刪除所有.posts – mononym

回答

9

嘗試

$('.more').bind('hover',function() 
{ 
    $(this).closest('.post').hide(); 
}); 

here是工作演示單類。
here是具有多個類的演示。

+0

作品在演示中,而不是在我的網站上,其他的一定是我的壞人 – mononym

+1

,一旦它消失了,下一個代替它,所以它立即刪除它們在單個懸停我會使用點擊事件 – mononym

+0

你能否提供給我們的網址看.. – Exception