Jquery delegate () (mouseover mouseout) events fire twice

I have the following mouse shooting script and the mouse is always twice! what do you suggest me to do wrong (cancel, return, for example)? I tried a few things, but nothing helped.

here is the code:

  $('#container').delegate('div.showmenu', 'mouseover mouseenter mouseout mouseleave', function(e){
  if (e.type === 'mouseover' || e.type==='mouseenter') { //jIE requires mouseenter, does not fire mouseover                                 
        if($(this).parents().closest('div').hasClass('whatever')){            
          alert(e.type);  //double-alerts mouseover

          menu.show();

    foldercmenu.hover(
        function(){
            $(this).show();                             
        },
        function(){
            $(this).hide();                                             
        }
    );                              

        }else {
    //do other stuff :-)
    }                                               
  }else if(e.type==='mouseout' || e.type==='mouseleave'){  //IE requires mouseleave, does not fire mouseout  
        alert(e.type);  //double-alerts mouseout
        menu.hide();
        $(this).unbind('mouseover mouseenter mouseout mouseleave');
  }
  //return false;   
});
+5
source share
2 answers

mouseoverand it mouseoutstarts when you enter / leave a child of this element, perhaps the effect that you see.

Another problem is that you are attaching a handler to both, mouseover and mouseenter ( mouseleaveand mouseout).

mouseenter mouseleave. jQuery .

+7

All Articles