Currently, I am working on a project to develop an image sorter using toggle buttons. However, I have encountered an issue where my function is only effective for the first image ID and not any others.
Below is the JavaScript function in question:
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 code snippet:
<button onclick=kitchen()>Kitchen</button>
<img src="https://picsum.photos/200/?" id="kitchen">
<img src="https://picsum.photos/200/?" id="kitchen">
The desired outcome is for the display block to toggle on all images with the ID "kitchen", but unfortunately, it is only affecting the first image currently.