jQuery “active” class assignment

前端 未结 3 1836
我在风中等你
我在风中等你 2021-01-02 21:16

All I am trying to accomplish is to be able to have an unordered list of links in which one is clicked, the parent list item is assigned the class \"active.\" Once another l

3条回答
  •  孤独总比滥情好
    2021-01-02 21:49

    Assumption: the UL element has the class 'linksList'.

    $('.linksList li a').click(function()
    {
      $('.linksList li').removeClass('active');
      $(this).parent().addClass('active');
    });
    

提交回复
热议问题