From 38b93edf209f6863dec5f4bdbdfc6f26ec589922 Mon Sep 17 00:00:00 2001 From: Marie Birner Date: Sat, 17 Feb 2024 16:38:58 +0100 Subject: [PATCH] [TASK] refactor js - mutliple button --- templates/app.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/templates/app.js b/templates/app.js index df7f187..cc7dc92 100644 --- a/templates/app.js +++ b/templates/app.js @@ -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", "")); + }); }); }