swap classes on click

后端 未结 2 622
無奈伤痛
無奈伤痛 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:40

    Alternatively you can use:

    $("#navigationagence ul li").click(function() {
        $(".currentagence").removeClass("currentagence");
        $(this).addClass("currentagence");
    });
    
    0 讨论(0)
  • 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");
    });
    
    0 讨论(0)
提交回复
热议问题