jquery add remove class

前端 未结 2 407
心在旅途
心在旅途 2020-12-15 07:21

I have 4 anchors, I want to add a class of current to an anchor as it is clicked and remove the class from the other 3 at the same time. Here\'s my code. what am I doing wro

2条回答
  •  时光说笑
    2020-12-15 08:05

    I think this will help you

    $("a").click(function() {
      $('a').removeClass('current');
      var id = $(this).attr('id');
      $('#'+id).addClass('current');
    });
    

提交回复
热议问题