2010-07-06 57 views
1

我有以下几点:查找特定类的下一个元素父里面jQuery的

<div class="container"> 
Test 1 
<div class="child">Testing</div> 
</div> 

<div class="container"> 
Test 2 
<div class="child">Testing</div> 
</div> 

<div class="container"> 
Test 3 
<div class="child">Testing</div> 
</div> 

我希望有孩子的div容器内部多数民众赞成在上空盘旋,以显示和隐藏,当鼠标离开容器。

我目前做的有:

 $('.container').hover(
      function() { 
       $(this).next('.child').show(); 
      }, 
      function() { 
       $(this).next('.child').hide(); 
      } 
     ); 

但似乎工作不。 任何建议表示感谢,谢谢。

回答

0

使用find()方法,而不是未来,因为它是一个子元素,而不是一个兄弟姐妹之一:

$('.container').hover(
     function() { 
      $(this).find('.child').show(); 
     }, 
     function() { 
      $(this).find('.child').hide(); 
     } 
    ); 
2

下一个()是兄弟姐妹,你应该使用儿童儿童:)...

$('.container').hover(
     function() { 
      $(this).children('.child').show(); 
     }, 
     function() { 
      $(this).children('.child').hide(); 
     } 
    ); 
相关问题