Design comparison
Solution retrospective
Any tip on how to achieve the completed design on the select tip buttons will be appreciated. Suggestions on how to write cleaner codes will also be welcomed. Thank you.
Community feedback
- @AyoubrabiaePosted about 1 year ago
To create selectable buttons that change their appearance when clicked, follow these steps:
1- Begin by defining a CSS class for these buttons, such as "selected__button." You can add any styling properties you'd like to this class, such as background color.
2- In your JavaScript code, if you've already stored these buttons in a variable, let's call it "numbers," you can add an event listener to each of them using a forEach loop.
3- Within this event listener, add the CSS class we created earlier to the clicked button using the
classList.add("selected__button")
method. This will change the button's appearance to indicate that it's selected.4- Don't forget to remove the "selected__button" class from any previously selected buttons. You can do this by selecting the buttons with this class using
document.querySelector(".selected__button")
and then removing the class withclassList.remove("selected__button")
.That's it! If you encounter any issues or have trouble understanding any part of this process, feel free to ask for assistance. Happy coding!
1@Bebe-devPosted about 1 year agoThank you. Removing it after was the main problem I had. I will work on this now@Ayoubrabiae
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