Target first level
  • s and not the nested
  • s
  • 后端 未结 6 1126
    无人共我
    无人共我 2020-12-07 19:51

    I have the following HTML:

    • A
      • subsection
    • B <
    6条回答
    •  庸人自扰
      2020-12-07 20:51

      I don't think your problem has been completely addressed (although there has been some good attempts). Your example problem deals with applying a style to a parent and preventing the child from inheriting the style -- which is a CSS problem.

      You could target the list items by knowing the parent element (as some have noted). Then add a class on hover.

      $('div > ul > li').hover(function(){
          $(this).addClass('myHover');
      },
      function(){
          $(this).removeClass('myHover');
      });
      

      And your CSS would have the class for the parent, and a negating style for the children:

      .myHover { font-weight: bold; }
      .myHover li { font-weight: normal; }
      

    提交回复
    热议问题