swap classes on click

后端 未结 2 624
無奈伤痛
無奈伤痛 2021-01-15 23:30

I have a list of 6 items that are in a global div (navigationagence) Right now I am able to add a class on click but right now they adds up which means that once my six item

2条回答
  •  北荒
    北荒 (楼主)
    2021-01-15 23:59

    You can use the siblings() method to get the other list items and remove the class from them:

    $("#navigationagence ul li").click(function() {
        $(this).addClass("currentagence").siblings().removeClass("currentagence");
    });
    

提交回复
热议问题