2013-10-14 53 views
0

我一直在尋找一種方法來解決這個問題;我有一個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

回答

1

假設:

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

這樣做:

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