Design comparison
SolutionDesign
Solution retrospective
How do I edit/change a css property on occurence of an event by referring to a class, using Javascript?
Community feedback
- @temideewanPosted over 4 years ago
//Select the element with class container let container = document.querySelector(".container"); //make something happen when we click on container container.addEventListener('click', ()=> container.classList.toggle("red")); //this presumes however that in whatever css file linked to your HTML document there are particular CSS rules for a class named red.
There are a bunch of different events you can respond to. Further information in the MDN documentation
2
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