Design comparison
SolutionDesign
Solution retrospective
Hello guys! How do i make to activate the active class in only 1 button, removing the class from the previous buttons i clicked?
Community feedback
- @AzzumarithmPosted over 1 year ago
Hey good job on completing this challenge.
Code Improvements
Before selecting another .rating-btn, you have to remove all the "active" class that you added to the previous .rating-btn meaning you have to loop again all the .rating-btn elements to find all the .rating-btn elements that contains the "active" class and remove the "active" class.
ratings.forEach((element) => { element.addEventListener("click", (e) => { //Code changes ratings.forEach((element) => { if (element.classList.contains("active"){ element.classList.remove("active") } } e.target.classList.add("active"); ratingScore = element.value; console.log(element); }); });
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