@machetio7
Posted
Great work!.
You can use JavaScript to add classes.
const items = document.getElementsByClassName("ranking__score__element");
for (let i = 0; i < items.length; i++) { items[i].addEventListener( "click", function () { items[i].classList.toggle("button__active");
//remove class in the other elements in the array ranking__score
const options = document.getElementsByClassName(
"ranking__score__element"
);
for (let index = 0; index < options.length; index++) {
if (index !== i) {
options[index].classList.remove("button__active");
}
}
},
false
); }
@lidiakrajewska
Posted
@machetio7 Thanks! I know, I applied a similar concept with forEach loop, but with each click event active class is removed from all elements and then added only to the one that was recently clicked. But your approach with checking it with if condition is a good idea.