Style parent li on child li:hover

前端 未结 2 1927
萌比男神i
萌比男神i 2020-12-07 04:28

I\'ve been digging all day to find out how to style the parent li when hovering on a child li element.

e.g.

  • Parent Element <
2条回答
  •  春和景丽
    2020-12-07 05:01

    The javascript:

    
    
    
    

    What this does is that when the mouse enters one of the child

  • elements, this adds the highlighted class to the parent
  • . And when the mouse leaves, the class is removed. So you just have to create a highlighted class now :)

    $(this).closest('.page_item') just searches for the closest parent element which matches the .page_item selector (so, the closest parent with a page_item class).

提交回复
热议问题