I have several lists, and when the user clicks on an item, I would like it to change the class to the current one, but if users then click on another item in the same list to switch it to the current one and remove the current one from the previous selected item.
any quick examples, I know that this probably already exists, but did not find a good example.
<ul id="list">
<li>item 1</li>
<li>item 2</li>
<li>item 3</li>
<li>item 4</li>
</ul>
So, if you click on element 1, it will be the current class, but will disconnect if you click on element 2.
source
share