I would like to ask someone who is knowledgeable in pure javascript, why this is happening.
I have a code that should only show the image when it is loaded (onload), but the function only fires when I wrap the onload directly in the img tag, when I put it in a block / javascript file it does not work ...
If I do: <img id="imagem" src="linkDaImagem" onload="this.style.display = 'block'" />
The image appears when loading.
But if I do this, 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, people? Do you have a solution for this?
I know Jquery is possible, but I ask for the solution in pure js, since I am learning it, and I have this doubt ...
Thanks to all who help, even more!