-
Notifications
You must be signed in to change notification settings - Fork 0
/
faq.js
27 lines (23 loc) · 1020 Bytes
/
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
document.addEventListener("DOMContentLoaded", () => {
const faqItems = document.querySelectorAll(".faq__item");
faqItems.forEach((item) => {
const questionButton = item.querySelector(".faq__question");
const answer = item.querySelector(".faq__answer");
questionButton.addEventListener("click", () => {
const isOpen = item.classList.contains("faq__item--open");
// Fermer tous les autres items
faqItems.forEach((otherItem) => {
otherItem.classList.remove("faq__item--open");
otherItem.querySelector(".faq__answer").style.maxHeight = null;
});
// Toggle l'état de l'item actuel
if (!isOpen) {
item.classList.add("faq__item--open");
answer.style.maxHeight = answer.scrollHeight + "px";
} else {
item.classList.remove("faq__item--open");
answer.style.maxHeight = null;
}
});
});
});