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 Page and DOM Events Practice

Samoina 220

@samoina

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

vinu cyril 980

@vinuman

Posted

Hello,

Good job completing the project.

To let the user know which button they have selected currently, update the JS like this,

Select all the buttons grouped under the class 'selections'. Declare a variable for the current active button. Add an event listener on the selections and declare the target. If the target has 'Button', apply background color and color properties to the target. Before executing this, check if there already exists an active button. If so, remove the background color and color of the same. Finally make the current target active button.:

Code: let activeButton;

selection.addEventListener('click', function(e){ const target = e.target;

if(target.matches('Button')){ if(activeButton) { activeButton.style.backgroundColor = ''; activeButton.style.color = ''; } target.style.backgroundColor = '#979797'; target.style.color = '#fff'; activeButton = target; } });

Hope this help. Happy coding!!!

Marked as helpful

1

Samoina 220

@samoina

Posted

@vinuman

Hi Vinu! Thank you for this feedback. I got a bit lost in this code snippet:

if(target.matches('Button'))..

what does 'Button' reference?

EDITED: I did figure it out and realized I was initially lost because my rating numbers were enclosed within list items <li> . But I updated the code so that the user sees their selection.

Again, thanks for the feedback - this was helpful.

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