Design comparison
Solution retrospective
Welcome any feed back. I wanted to use an addEventListener instead of having an 'onclick' assigned to each rating div to tell which div was clicked. What I attempted is in the js file but commented out. Does anyone have an idea how to convert what I have? Not sure how to write a function or add to existing function to not allow a submit and show an alert if there was not a rating selected.
Community feedback
- @GFJankavsPosted over 2 years ago
If you wanted to addEventListener() instead of built-in onclick attribute, then you could have:
- created a div element;
- use for loop to assign necessary values (classList.add, addEventListener, etc.);
- push each element into variable with an array;
- then, using forEach() on the variable with array of your newly created elements, append them to the parent container (class="rating-container).
Mabey could be done easier, but this was what first came into my mind when it comes to addEventListener(). Hope it helps!
1
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