Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found

Submitted

Interactive Rating Component

P

@unachoza

Desktop design screenshot for the Interactive rating component coding challenge

This is a solution for...

  • HTML
  • CSS
  • JS
1newbie
View challenge

Design comparison


SolutionDesign

Community feedback

kimchiver 90

@kimchiver

Posted

document.querySelectorAll returns an array, so you can check each element of the array ( if document.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 helpful

0

P

@unachoza

Posted

@kimchiver thank you; I appreciate your review! Reminding me that document.querySelectorAll returns an array, I realized I can use forEach to get the removal task done :)

0

@srirakeshv

Posted

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 GitHub
Discord logo

Join 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