[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() {
const openBtn = document.querySelector('.open-js');
const closeBtn = document.querySelector('.close-js');
const openBtns = document.querySelectorAll('.open-js');
const closeBtns = document.querySelectorAll('.close-js');
const detailElements = document.querySelectorAll('details');
openBtn.addEventListener('click', function(){
detailElements.forEach((detail) => detail.setAttribute("open", ""));
openBtns.forEach(function(openBtn) {
openBtn.addEventListener('click', function(){
detailElements.forEach((detail) => detail.setAttribute("open", ""));
});
});
closeBtn.addEventListener('click', function(){
detailElements.forEach((detail) => detail.removeAttribute("open", ""));
closeBtns.forEach(function(closeBtn) {
closeBtn.addEventListener('click', function(){
detailElements.forEach((detail) => detail.removeAttribute("open", ""));
});
});
}