CSS/JQuery Hover Affect Only Hovered Element and Not Parent

后端 未结 5 1442
说谎
说谎 2021-01-26 11:07

I have a list of nested items, each which has it\'s own edit link.

5条回答
  •  鱼传尺愫
    2021-01-26 11:32

    This is not exactly the same as your problem but it may help somebody else. The idea is to highlight the top hovered child without affecting the parents below: http://jsfiddle.net/skibulk/mcq6Lvw3/6/

    $("div").hover(
        function (e) {
            e.stopPropagation();
            $(this).addClass('active').parents().removeClass('active');
        },
        function (e) {
            $(this).removeClass('active').parent().addClass('active');
        }
    );
    

提交回复
热议问题