Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found

Submitted

A Mobile First Design of a FAQ Accordion

@DR-KSP-VIRUS

Desktop design screenshot for the FAQ accordion coding challenge

This is a solution for...

  • HTML
  • CSS
  • JS
1newbie
View challenge

Design comparison


SolutionDesign

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

Raza Abbas 790

@RazaAbbas62

Posted

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 helpful

1

Please log in to post a comment

Log in with GitHub
Discord logo

Join 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