jQuery add class to current li and remove prev li when click inside li a

后端 未结 7 524
执笔经年
执笔经年 2020-12-28 08:55

here is html:

7条回答
  •  自闭症患者
    2020-12-28 09:51

    Use on('click') if you are using latest version of jquery

    $('ul li a').on('click', function(){
        $(this).parent().addClass('current').siblings().removeClass('current');
    });
    

    A fiddle is here.

提交回复
热议问题