Does jQuery have a handleout for .delegate('hover')?

前端 未结 5 1370
被撕碎了的回忆
被撕碎了的回忆 2020-11-30 03:58

I am trying to use:

$(\'mydiv\').delegate(\'hover\', function() {  
    $(\'seconddiv\').show();  
}, function() {  
    //For some reason jQuery won\'t ru         


        
5条回答
  •  北海茫月
    2020-11-30 04:34

    EDIT: misinformation removed.

    If you want to use the hover() method without delegation, working code would look like this:

    $('#mydiv').hover(function() {  
        $('#seconddiv').show();  
    }, function() {  
        $('#seconddiv').hide();  
    });
    

    Second of all, delegate is to assign an event handler to a child, so you need to specify a selector first. If you need to make sure this event handler exists for dynamically added elements, I would prefer .live() in this case with mouseenter and mouseleave.

    $('#mydiv').live('mouseenter', function() {  
        $('#seconddiv').show();  
    }).live('mouseleave', function() {  
        $('#seconddiv').hide();  
    });
    

提交回复
热议问题