Design comparison
SolutionDesign
Community feedback
- @kimchiverPosted about 1 year ago
document.querySelectorAll
returns an array, so you can check each element of the array ( ifdocument.querySelectorAll(".rating-value")[i].classList.contains("active")
). otherwise you can store a reference to the previous selected item in a global variable:let previousSelected = null ratingsContainer.addEventListener('click', (e) => { ... if ( previousSelected ) previousSelected.classList.remove('active'); previousSelected = e.target; e.target.classList.add('active') ... }
Marked as helpful0@unachozaPosted about 1 year ago@kimchiver thank you; I appreciate your review! Reminding me that
document.querySelectorAll
returns an array, I realized I can useforEach
to get the removal task done :)0 - @srirakeshvPosted about 1 year ago
instead u use for each for buttons and then pass argument then for that argument add event listerner then it will change the rating button once u select also
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