-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
23 lines (19 loc) · 738 Bytes
/
script.js
File metadata and controls
23 lines (19 loc) · 738 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
const headers = document.querySelectorAll('.accordion-header');
headers.forEach(header => {
header.addEventListener('click', function() {
const item = this.parentElement;
const content = item.querySelector('.accordion-content');
document.querySelectorAll('.accordion-item').forEach(otherItem => {
if (otherItem !== item) {
otherItem.classList.remove('active');
otherItem.querySelector('.accordion-content').style.maxHeight = null;
}
});
item.classList.toggle('active');
if (item.classList.contains('active')) {
content.style.maxHeight = content.scrollHeight + 'px';
} else {
content.style.maxHeight = null;
}
});
});