showing results for - "javascript code for accordion questionnaire"
Scot
27 Jun 2020
1// ".question__component" is the div element that contains the question and 
2// the hidden description block as well.
3
4document.querySelectorAll(".question__component").forEach((question) => {
5  return question.addEventListener("click", () => {
6    question.parentNode
7      .querySelectorAll(".question__component")
8      .forEach((component) => {
9        if (component === question) {
10          return;
11        }
12        if (component.classList.contains("active")) {
13          component.classList.toggle("active");
14        }
15      });
16    question.classList.toggle("active");
17  });
18});