[TASK] refactor js - mutliple button
All checks were successful
CI/CD Pipeline / deploy-main (push) Successful in 6s

This commit is contained in:
Marie Birner 2024-02-17 16:38:58 +01:00
parent cefbb1d38a
commit 38b93edf20

View File

@ -3,15 +3,19 @@ document.addEventListener('DOMContentLoaded', function() {
}); });
function toggleSummary() { function toggleSummary() {
const openBtn = document.querySelector('.open-js'); const openBtns = document.querySelectorAll('.open-js');
const closeBtn = document.querySelector('.close-js'); const closeBtns = document.querySelectorAll('.close-js');
const detailElements = document.querySelectorAll('details'); const detailElements = document.querySelectorAll('details');
openBtns.forEach(function(openBtn) {
openBtn.addEventListener('click', function(){ openBtn.addEventListener('click', function(){
detailElements.forEach((detail) => detail.setAttribute("open", "")); detailElements.forEach((detail) => detail.setAttribute("open", ""));
}); });
});
closeBtns.forEach(function(closeBtn) {
closeBtn.addEventListener('click', function(){ closeBtn.addEventListener('click', function(){
detailElements.forEach((detail) => detail.removeAttribute("open", "")); detailElements.forEach((detail) => detail.removeAttribute("open", ""));
}); });
});
} }