Design comparison
SolutionDesign
Solution retrospective
I tried as much as I could but couldn't figure out how to collapse any other 'active' toggles when I click another question. I had so much fun doing this tho!
Thank you for checking out :)
Community feedback
- @nmorajdaPosted over 3 years ago
How to collapse any other 'active' toggles when I click another question?
Something like that:
const toggles = document.querySelectorAll('.toggle'); function collapseAll() { toggles.forEach(toggle => toggle.parentNode.classList.remove('active')); } toggles.forEach(toggle => { toggle.addEventListener('click', () => { collapseAll(); toggle.parentNode.classList.toggle('active'); }); });
1@creativehkimPosted over 3 years ago@nmorajda thanks for the comment! I will definitely try this code and update it! Happy coding :)
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