Submitted about 2 years ago
Landing page with HTML5/SCSS AND VANILLA JAVASCRIPT
@SatellitePeace
Design comparison
SolutionDesign
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.
Community feedback
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