-2
I am developing a code to change the image when it is clicked, this with several Divs, ids to be exchanged for the same image. I even managed to change the first one, but the rest do not change, because of the ID. But I could not think or find anything similar.
<img src="images/coração.png" class="checkbox-7" id="changeimg" onclick="changeImg();">
<img src="images/coração.png" class="checkbox-7" id="changeimg2" onclick="changeImg();">
<img src="images/coração.png" class="checkbox-7" id="changeimg3" onclick="changeImg();">
<img src="images/coração.png" class="checkbox-7" id="changeimg4" onclick="changeImg();">
function changeImg () {
document.getElementById("changeimg").src="images/coracao-preenchido.png";
}
Study on foreach()
– hugocsl
You want to exchange all images by clicking on one of them, or change only the one that was clicked?
– Andre
@user140828 exchange only the image that was clicked.
– JTeles