I'm trying to create an image sorter with toggle buttons, but my function is only working for the first image with the ID and not any others.
This is the JS function
function kitchen() {
var x = document.getElementById("kitchen");
if (x.style.display === "none") {
x.style.display = "block";
} else {
x.style.display = "none";
}
}
Here is the html button
<button onclick=kitchen()>Kitchen</button>
<img src="https://picsum.photos/200/?" id="kitchen">
<img src="https://picsum.photos/200/?" id="kitchen">
I'm expecting it to toggle display block on all images with the id "kitchen" but it is only doing the first image.