Answers for "javascript code for accordion questionnaire"

0

javascript code for accordion questionnaire

// ".question__component" is the div element that contains the question and 
// the hidden description block as well.

document.querySelectorAll(".question__component").forEach((question) => {
  return question.addEventListener("click", () => {
    question.parentNode
      .querySelectorAll(".question__component")
      .forEach((component) => {
        if (component === question) {
          return;
        }
        if (component.classList.contains("active")) {
          component.classList.toggle("active");
        }
      });
    question.classList.toggle("active");
  });
});
Posted by: Guest on July-07-2021

Code answers related to "javascript code for accordion questionnaire"

Code answers related to "Javascript"

Browse Popular Code Answers by Language