add/remove active class for ul list with jquery?

前端 未结 5 875
太阳男子
太阳男子 2020-12-29 07:18

I\'m trying to remove and set an active class for a list item every time it\'s clicked. It\'s currently removing the selected active class but isn\'t setting it. Any idea w

5条回答
  •  天涯浪人
    2020-12-29 08:12

    this will point to the

      selected by .nav-list. You can use delegation instead!

      $('.nav-list').on('click', 'li', function() {
          $('.nav-list li.active').removeClass('active');
          $(this).addClass('active');
      });
      

提交回复
热议问题