jquery list item class toggle

后端 未结 5 2143
悲哀的现实
悲哀的现实 2021-02-11 08:19

I have a simple function to toggle list item class from \"active\" to \"inactive\". What is the most efficient way (i.e., using the least amount of code) to set all other list i

5条回答
  •  星月不相逢
    2021-02-11 08:54

    $('ul li').click(function() {
        $('ul li').each(function() {
           $(this).removeClass('active'); 
        });
        $(this).addClass('active');  
    });
    

    JSFiddle

提交回复
热议问题