From c593843792d2578de8bc4358de151e922be2f905 Mon Sep 17 00:00:00 2001 From: Kaillr Date: Wed, 24 Jul 2024 19:51:07 +0200 Subject: [PATCH] Updated faq toggle --- frontend/js/faqs.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/frontend/js/faqs.js b/frontend/js/faqs.js index 9316c55..f661bce 100644 --- a/frontend/js/faqs.js +++ b/frontend/js/faqs.js @@ -4,7 +4,12 @@ const questions = document.querySelectorAll('.question'); // Loop through each question element and add a click event listener questions.forEach(question => { question.addEventListener('click', () => { - // Toggle the 'active' class on the parent 'faqs' element + // Remove the 'active' class from all '.faqs' elements + document.querySelectorAll('.faqs.active').forEach(faq => { + faq.classList.remove('active'); + }); + + // Toggle the 'active' class on the parent '.faqs' element of the clicked question question.closest('.faqs').classList.toggle('active'); }); });