const accordions = document.querySelectorAll(".accordion"); for (const accordion of accordions) { let expandButton = accordion.querySelector('.more-info input[type="checkbox"]'); let content = accordion.querySelector(".content"); accordion.style.height = expandButton.addEventListener("change", (e) => { if (e.target.checked) { content.style.maxHeight = content.scrollHeight + "px"; content.style.marginTop = "24px"; } else { content.style.marginTop = 0; content.style.maxHeight = null; } }); } window.addEventListener("resize", (e) => { for (const accordion of accordions) { let content = accordion.querySelector(".content"); if (accordion.querySelector('.more-info input[type="checkbox"]').checked) { content.style.maxHeight = content.scrollHeight + "px"; content.style.marginTop = "24px"; } else { content.style.marginTop = 0; content.style.maxHeight = null; } } });