
Design comparison
Solution retrospective
making the numbers to be vertically and horizontally centered was a little bit difficult but I used a grid styling and place-items:centered. Check my repository for clarity.
What specific areas of your project would you like help with?I would like to get feedback on how to use event delegation on this
Community feedback
- @calvinvinPosted 3 months ago
Works well!
For event delegation to add event listener on buttons 1~5, the following would work for your codes:
const divButtons = document.getElementById("no-btn"); const buttonIdList = ['one', 'two', 'three', 'four', 'five']; divButtons.addEventListener("click", function(event) { if ( buttonList.includes(e.target.getAttribute("id") ) { ......; } })
But I think event delegation wound not be needed if using React library?
To make the codes better, use native html element would enhance semantics and accessibility. For example, replace the
<div id="one">
with<button id="one">
. In this challenge scenario, I think make it a form and assign the buttons 1~5 with<input type="radio" name="score" value="1">
and use the submitted button to submit the form would be even better. By using<input>
, it is also easier to style the selected button (score 1~5) by using CSSinput:checked
pseudo-class selector.Marked as helpful0@Michael-AlansPosted 3 months ago@calvinvin Thanks so much, I really appreciate your correction
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