Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Ellis01's avatar

FAQs not working properly

Hi everyone, I have created an FAQs section in a blog post. It went well though but there is an issue, When I click a question its answer appears but when I click the other one, the first one is supposed to close as the second one opens. But in my case, both stay open, in fact, all of them. I want one of them to be opened when I click it and when I click the next one I want the previous one to be closed automatically.

Any assistance would be appreciated.

0 likes
1 reply
Pauli01's avatar
Pauli01
Best Answer
Level 1

@ellis01 Well doesn't seem to be a big problem, it would have been easier if you had shared your code. Anyhow, here is my function that I have used the following function: function toggleAnswer(index) { const answer = document.getElementById(faq-answer-${index}); if (answer.style.display === "none" || answer.style.display === "") { answer.style.display = "block"; } else { answer.style.display = "none"; } } Make some adjustments according to your function and field names and hopefully it will work well.

Please or to participate in this conversation.