2

i want to make one of the images disappear (opacity 0 ) but when the images completely load here is the code :

var imges = document.getElementsByTagName('img');


imges[0].style.opacity=0;

how to write the event of when the images load completely then do this ?

of course with vanilla javascript

0

1 Answer 1

2

You can dynamically append to it the dom to ensure the event listener is on there before it is parsed by the browser like below.

var img = new Image();
img.onload = function () {
   this.style.opacity = 0;
}
img.src = "The url or path to your image.";
Sign up to request clarification or add additional context in comments.

1 Comment

my onload function never gets called. Src is valid.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.