2012-07-24 71 views
0

我的代碼是:如何在每個div中顯示一個元素?

<div id="post"> 
<a href="./?act=remove&post_id=13" id="remove">Delete</a> 
<b>Admin</b> says: 
"Hi to all my frends!" 
<br> 
7 hours ago &middot; 
<a id="like" href="./?act=like&id=13" title="No one likes">Like</a> &middot; 
<a id="dislike" href="./?act=dislike&id=13" title="No one dislikes">Dislike</a> 
</div> 

我也有多個帖子像上面這個...我怎樣才能讓jQuery的,每次我「鼠標懸停」 #post,裏面 #post的#remove出現?

+1

不要在多個元素上使用相同的ID。你到目前爲止嘗試過哪些代碼? – MrOBrian 2012-07-24 22:26:17

回答

2

首先我想你想用class="post"class="remove",如果你有多個這樣的職位。然後,你可以做這樣的(the code on jsfiddle):

$(".post").on("mouseover", function(){ 
    $(this).find(".remove").show(); 
}).on("mouseout", function(){ 
    $(this).find(".remove").hide(); 
}); 

你可能要考慮一些jQuery函數:.on().mouseover().mouseout().hover()