Jquery hover only at the last element
I have following html structure:
<div id="123" class="test">
<div class="testMessage">Foo</div>
<div><div class="testDate">2010</div></div>
<div id="127" class="test">
<div class="testMessage">Bar</div>
<div><div class="testDate">2011</div></div>
</div>
</div>
And following JS code:
$(".test").live({
mouseenter:
function()
{
$(this).find(".testDate").show();
},
mouseleave:
function()
{
$(this).find(".testDate").hide();
}
});
The problem is that when mouse pointer is at #127
.testDate
in #123
also displayed. I think it's because ho开发者_C百科ver works for parent element. How to fix it?
Thanx!
$(".test").live({
mouseenter: function() {
$('.testDate:first', this).show();
},
mouseleave: function() {
$('.testDate:first', this).hide();
}
});
I think this is because you have one element '.test' inside another '.test'. If you split them, your code will work. Here is working example.
精彩评论