Hi i wrote some code to show and hide a paragraph in a card using Javascript. This works perfectly fine on the first card, but it doesn't work on any of the other cards. This shouldn't be very difficult, but it's a school project and there are a few rules. I cannot use div, class or id. It also has to be semantic, so the checkbox hack and the onclick attribute are not allowed.
This is my code:
var section = document.querySelectorAll('section > summary > p');
var button = document.querySelectorAll('section > summary > button');
var show = function () {
section.classList.toggle('show')
}
button.addEventListener('click', show());
section summary p {
display: none;
}
section summary p.show {
display: block;
}
<body>
<main>
<!--first card-->
<section>
<!-- Top part-->
<span> <img> </span>
<!-- Bottom part-->
<summary>
<button>show paragraph</button>
<!--This button triggers the toggle-->
<h2></h2>
<h3></h3>
<p>I'm trying to show and hide this p <a href="#">lees meer</a></p>
<footer></footer>
</summary>
</section>
<!--second card-->
<section>
<!-- Top part-->
<span> <img> </span>
<!-- Bottom part-->
<summary>
<button>show paragraph</button>
<h2></h2>
<h3></h3>
<p>I'm trying to show and hide this p <a href="#">lees meer</a></p>
<footer></footer>
</summary>
</section>
</main>
</body>
This is the link to my pen: https://codepen.io/SummerD/pen/MEMMNB
I have not seen any solutions to this problem without using classes. I hope you can help me!