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

前端 未结 5 1193
独厮守ぢ
独厮守ぢ 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:22

    You can try this

    $('#menu li').live('mouseenter mouseleave', function (e) {
        if (e.type == 'mouseenter') {
            //Show ul
        } else {
            //Hide ul
        }
    });
    

    The advantage is a usage of event delegation. Good luck!

提交回复
热议问题