3
I’d like to ask someone who understands pure javascript, why this is happening.
I have a code that should only show the image when it is loaded (onload), only the function only fires when I Seto onload direct in the img tag, when I put in a block/javascript file does not work...
if I do: <img id="imagem" src="linkDaImagem" onload="this.style.display = 'block'" />
image appears when loading.
But if I do so, in a script block or external file, it does not work:
document.getElementById('imagem').addEventListener("load", function(){
this.style.display = 'block';
});
Why does this happen, guys? There’s some solution to this?
I know that via Jquery is possible, but I ask for the solution in pure js, because I am learning it, and I have this doubt...
Thanks to all who help, see you later!