Latest solutions
Latest comments
- @jplawrence@danyrszz
i have problems with my html semantics but i can help with the JS part:
you can add the same class to each one of your li elements, then do a querySelectorAll to assign each one of them to an array, then you can do two things: either add an eventlistener to the ul element (container) to manage each one of the li clicks, or add an event listener to each one of li elements, so that when you click you can have the exact clicked element and you'll be able to do something like "event.target.classList.add("selected") where selected will have the desired background color, then to remove the previous selected element you can at each click traverse the array and do something like "event.target.classList.remove("selected") for each li element.
This way you write the event just once and you can add as many elements as you like without having to touch the js.
That's kinda the way i did it, hope i made myself clear
Marked as helpful