admin管理员组

文章数量:1323335

I am trying to show an anchor link when a div is hovered. This is working fine, but when I hover over the link itself, it flashes, when it should just stay. I tried a regular hover function on the anchor link and that didn't work... This is my js:

$('.div_mayKnowUser').live("mouseover", function(){
   $(this).find('.a_ignoreUser').fadeIn();
});
        
$('.div_mayKnowUser').live("mouseout", function(){
   $(this).find('.a_ignoreUser').fadeOut();
}); 

and my HTML:

<div class="div_mayKnowUser">
    <a href="" class="a_ignoreUser">a link</a>
</div>

I am trying to show an anchor link when a div is hovered. This is working fine, but when I hover over the link itself, it flashes, when it should just stay. I tried a regular hover function on the anchor link and that didn't work... This is my js:

$('.div_mayKnowUser').live("mouseover", function(){
   $(this).find('.a_ignoreUser').fadeIn();
});
        
$('.div_mayKnowUser').live("mouseout", function(){
   $(this).find('.a_ignoreUser').fadeOut();
}); 

and my HTML:

<div class="div_mayKnowUser">
    <a href="" class="a_ignoreUser">a link</a>
</div>
Share edited Dec 7, 2022 at 19:21 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Jun 13, 2011 at 21:30 webwrkswebwrks 11.9k5 gold badges26 silver badges21 bronze badges 1
  • you should use Delegate, chain your jQuery methods and search not by class only, but by Tag name as well. – vsync Commented Jun 13, 2011 at 21:36
Add a ment  | 

1 Answer 1

Reset to default 9

"mouseover" => "mouseenter"

"mouseout" => "mouseleave"

worth a read => http://www.quirksmode/js/events_mouse.html

Edit: regarding live and mouseenter/mouseleave, it seems there's a known bug that hasn't been fixed, see the examples on the ments.

本文标签: javascriptLive mouseover eventStack Overflow