How do I ignore mouse events on child elements in jQuery?

前端 未结 5 1195
独厮守ぢ
独厮守ぢ 2020-12-08 10:38

I have an unordered list with mouseover and mouseout events attached to the li elements. Each contains a link and there is a bit of padding in the li. When I mouseover the l

5条回答
  •  鱼传尺愫
    2020-12-08 11:30

    It seems I've found the answer to my own question. For anyone who might have the same problem; try this code instead. It seems hover doesn't bubble into child elements like the other mouse events do.

    jQuery('#menu li').hover(
        function() {
            jQuery(this).children('ul').show('fast');
            return false;
        },
        function() {
            jQuery(this).children('ul').hide('fast');
            return false;
        }
    );
    

提交回复
热议问题