Landing page with HTML5/SCSS AND VANILLA JAVASCRIPT

Solution retrospective
Is there any way i can make a faq to close when another is opened.
I tried this
openFaq();
function openFaq(e) {
for (let i = 0; i < showAnswer.length; i++) {
showAnswer[i].addEventListener("click", (e) => {
hideFaqs();
answers[i].classList.toggle("open");
closeFaq[i].classList.toggle("active");
e.preventDefault();
});
}
}
function hideFaqs() {
answers.forEach((ans) => {
ans.classList.remove("open");
});
}
which worked except for the fact that i could no longer close an faq without leaving another one open.
Please log in to post a comment
Log in with GitHubCommunity feedback
No feedback yet. Be the first to give feedback on Nneoma Njoku's solution.
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