Design comparison
Solution retrospective
Hello Everyone
I am very excited that I am able to submit the solution to this design as early as possible.
I had a long night coding and debugging.
Please access my js
component. Please tell me how to write it better.
Thank you.
Community feedback
- @RazaAbbas62Posted 10 months ago
it looks good but here's how you can make your js file better: ` 'use strict';
const openAccordion = document.querySelectorAll('.topic');
openAccordion.forEach((element) => { element.addEventListener('click', function () { let contentText = this.nextElementSibling; contentText.classList.toggle('active');
if (contentText.classList.contains('active')) { contentText.style.maxHeight = `${contentText.scrollHeight}px`; } else { contentText.style.maxHeight = null; }
}); });`
and u can add active class in your CSS file , just as `/* Add this to your CSS */
.topic-content { max-height: 0; overflow: hidden; transition: max-height 0.3s ease-out; /* Add a smooth transition effect */ }
.topic-content.active { max-height: 200px; /* Adjust the value based on your design / / Add any other styles you want for the active state */ } ` I hope this is much better
Marked as helpful1
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