2010-11-16 67 views
0

我有一系列隱藏了說明div的圖像。我試圖在懸停事件中顯示說明。我看不到它的工作。這是代碼。如何在一系列圖像上顯示鼠標上的隱藏div

<div class="peopleImage" id="image1"> 
    <img src="image1.jpg"> 
    <div class="peopleInfo">Description goes here</div> 
</div> 


<div class="peopleImage" id="image1"> 
    <img src="image1.jpg"> 
    <div class="peopleInfo">Description goes here</div> 
</div> 

<div class="peopleImage" id="image1"> 
    <img src="image1.jpg"> 
    <div class="peopleInfo">Description goes here</div> 
</div> 

這裏是我的工作了jQuery:

$(".peopleImage").hover(function() { 
    var peopleInfo = $(this).closest('.peopleInfo'); 
    peopleInfo.show(); 
}); 

好像沒有什麼改變。任何建議,將不勝感激!

回答

0

嘗試

(".peopleInfo").show() 

給sepearte ID爲每個格並嘗試調用show()與ID。

,這將是更好的

+0

肯定不是更好的方法來硬編碼所有的ID! – 2010-11-16 04:18:42

1

試試這個:

$(".peopleImage").hover(function() { 
    $('.peopleInfo', this).show(); 
}, function() { 
    $('.peopleInfo', this).hide(); 
}); 

jsFiddle example

相關問題