[TASK] add functions open and close

This commit is contained in:
Marie Birner 2024-02-17 16:27:15 +01:00
parent 5de6732e7e
commit 200653b74e
2 changed files with 8 additions and 8 deletions

View File

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

View File

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