Create Eventlisteners for detailstag dynamically?

Why is this working: const details = document.querySelector(‘details’) document.getElementById(“details1”).addEventListener(“toggle”, event => { if (details1.open) { changeText1(“open”); } else { changeText1(“closed”); } }); document.getElementById(“details2”).addEventListener(“toggle”, event => { if (details2.open) { changeText2(“open”); } else { changeText2(“closed”); }; }); function changeText1(status) { if(status == “open”) { document.getElementById(“p1”).innerText = “opened”; } else if (status == “closed”) { document.getElementById(“p1”).innerText =… Read More Create Eventlisteners for detailstag dynamically?

How can I change picture on opening & closing details/summary?

This is my first JavaScript ever. It took lots of time but can’t get it to work. Obviously, what it should do is changing the picture when the ‘details/summary’ part is opened. FYI it’s a follow-up from this problem that I’m trying to solve. Anyone see what I’m doing wrong? <body> <script type=”text/javascript”> function changeImage(a)… Read More How can I change picture on opening & closing details/summary?