So I have a div where the image is shown by default, and the list is hidden. But clicking the button shows the list and hides the image. There will be a grid of these item
divs.
<div class="item">
<div class="item__content">
<img src="..." alt="<Relevant text>" id="image">
<ul class="hidden" id="list">
<li>Detail 1</li>
<li>Detail 2</li>
<li>Detail 3</li>
<li>Detail 4</li>
</ul>
</div>
<div class="item__heading">
<div class="item__heading__text">
<h3>Item name</h3>
<h4>Item brand</h4>
</div>
<button onclick="toggleContent()" aria-controls="image list">Details</button>
</div>
</div>
And currently I just have a CSS class like
.hidden {
display: none;
}
and a JS function
function toggleContent() {
const image = document.getElementById("image");
const list = document.getElementById("list");
image.classList.toggle("hidden");
list.classList.toggle("hidden");
}
Is there a better way to approach this? I'm unsure about the method of hiding things, and also if there is any need for aria-hidden
?
I should probably note that the alt
text of the image is important, as the image displays information that users would otherwise not be able to decude.