HTML
    | Change particular
  • color onclick and other
  • in the same
      to default color

前端 未结 6 1264
有刺的猬
有刺的猬 2021-01-18 22:12

I want to have 5 lists such than when any of them is clicked, it turns to green and turn the other lists to black if any of them is green.

Here\'s m

6条回答
  •  盖世英雄少女心
    2021-01-18 22:47

    It works for me with jquery version 2.1.1, Please try this

    $(document).on('click', '#menu li', function(){
       $('.#menu li').removeClass('selected');
       $(this).addClass('selected');
    });
    

    And add this in CSS file.

    #menu li.selected {
       background-color: rgb(2, 95, 191);
    }
    

提交回复
热议问题