george george - 1 year ago 34
HTML Question

How to add class to list item and remove it from previous item

I need add class

to item list on click and remove it when I click on the next item.


<ul class="navbar-custom clearfix">
<li><a href="#start"></a></li>
<li><a href="#description"></a></li>
<li><a href="#syntax"></a></li>
<li><a href="#scrollbar"></a></li>
<li><a href="#rotations"></a></li>
<li><a href="#rotations-rotated"></a></li>
<li><a href="#source"></a></li>
<li><a href="#follow"></a></li>


$("nav").find("li").click(function () {

Answer Source

For doing that, toggleClass is not enough,

$("nav").find("li").click(function () {
    //remove all the orange class set with the li elements except the current element
    // add class orange to the current element.