dlseitz.dev-frontend/src/scripts/services.js

17 lines
734 B
JavaScript

document.addEventListener('DOMContentLoaded', function() {
const accordionHeaders = document.querySelectorAll('.accordion-header');
accordionHeaders.forEach(header => {
header.addEventListener('click', function() {
const content = this.nextElementSibling;
// Check if maxHeight has a value. If it does, the accordion is open.
if (content.style.maxHeight) {
content.style.maxHeight = null; // Close the accordion
} else {
// The accordion is closed, open it by setting max-height to its scroll height
content.style.maxHeight = content.scrollHeight + 'px';
}
});
});
});