jquery悬停在孩子的影响其他孩子

问题描述:

我一直在寻找一种方法来解决这个问题;我有一个div,里面有两件事:第一个是img,第二个是div。我想拥有它,这样,一旦你悬停在img上,div就会出现。但因为img和div都是第一个div的子项,所以我很难做到这一点。jquery悬停在孩子的影响其他孩子

我试着这样做:

 $('.mydiv img').hover(
    function() 
    { 
     $(this).parent().children(':nth-child(1)').removeClass('hidden'); 
    } 

,但它不工作

<div class='mydiv' style='position: relative; top:216; left:22%;' href='#' id='1'> 
    <img src='assets/this/1.png'> 

    <div id='Jumper' class='hidden'> <img src='assets/this/G.png' /> 
     <table> 
      <tr> 
       <th>Name</th> 
       <th>DF-0</th> 
      </tr> 
      <tr> 
       <td>replace_me</td> 
       <td>70</td> 
      </tr> 
     </table> 
    </div> 
</div> 
+1

也发布HTML其他方面,我们如何能看到你想要访问什么? – rorypicko

+0

你应该学习jquery的[DOM遍历方法](http://api.jquery.com/category/traversing/) –

+0

是的,HTML不像你最初描述的那样。 : -/ – isherwood

假设:

<div class="mydiv"> 
    <img /> 
    <div></div> 
</div> 

这样做:

$('.mydiv img').hover(function() { 
    $(this).next('div').show(); 
});