-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfaq.js
34 lines (29 loc) · 1.35 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
33
34
document.addEventListener('DOMContentLoaded', function() {
const faqItems = document.querySelectorAll('.faq-item');
faqItems.forEach(item => {
const question = item.querySelector('.faq-question');
const answer = item.querySelector('.faq-answer');
if (question && answer) {
answer.style.maxHeight = '0px';
question.addEventListener('click', function() {
const isActive = item.classList.contains('active');
// Close all other items
faqItems.forEach(otherItem => {
if (otherItem !== item && otherItem.classList.contains('active')) {
otherItem.classList.remove('active');
const otherAnswer = otherItem.querySelector('.faq-answer');
otherAnswer.style.maxHeight = '0px';
}
});
// Toggle current item
if (!isActive) {
item.classList.add('active');
answer.style.maxHeight = answer.scrollHeight + 'px';
} else {
item.classList.remove('active');
answer.style.maxHeight = '0px';
}
});
}
});
});