-
Notifications
You must be signed in to change notification settings - Fork 334
/
faq.js
32 lines (28 loc) · 1.14 KB
/
faq.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const accordions = document.querySelectorAll(".accordion");
accordions.forEach((accordion, index) => {
const header = accordion.querySelector(".accordion__header");
const content = accordion.querySelector(".accordion__content");
const icon = accordion.querySelector(".accordion__icon i");
header.addEventListener("click", () => {
const isOpen = content.style.height === `${content.scrollHeight}px`;
accordions.forEach((a, i) => {
const c = a.querySelector(".accordion__content");
const ic = a.querySelector(".accordion__icon i");
if (i === index) {
c.style.height = isOpen ? "0px" : `${c.scrollHeight}px`;
ic.classList.toggle("ri-add-line", isOpen);
ic.classList.toggle("ri-subtract-fill", !isOpen);
// add a new class active to the active accordion
// removeActiveClasses();
a.classList.toggle("active");
// end of block
} else {
c.style.height = "0px";
ic.classList.add("ri-add-line");
ic.classList.remove("ri-subtract-fill");
// remove active classes for other accordions
a.classList.remove("active");
}
});
});
});