Design comparison
SolutionDesign
Community feedback
- @machetio7Posted over 2 years ago
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
); }
0@lidiakrajewskaPosted over 2 years ago@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.
0 - @skyv26Posted over 2 years ago
Good Work !! Keep it up.
0
Please log in to post a comment
Log in with GitHubJoin our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord