I'm trying to set a html img
within a button .button__image
and change a hidden span to display:block;
on an image error (across multiple classes, which is why I'm not using getElementById
), but I'm receiving an error:
ERROR
Uncaught TypeError: document.getElementsByClassName(...).addEventListener is not a function
HTML
<img src="images/logo_image.svg" class="button__image"><span class="hidden"/>stuff</span>
JS
document.getElementsByClassName("button__image").addEventListener("error", unhideHiddenFunction);
function unhideHiddenFunction() {
alert('image error');
document.getElementsByClassame("hidden").style.display = "block";
}