Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR HTML

javascript wait for image to load

<!-- new Image(); -->
<script>
	const image = new Image();
	// make sure onload is set before src is set
	image.onload = function() {
		console.log("Image loaded:", image.src);
	};
	image.src = "image url";
</script>
<!-- <img> -->
<img id="img" src="image url"></img>
<script>
	const img = document.getElementById("img");
	img.onload = function() {
		 console.log("Image loaded:", img.src);
	};
</script>
 
PREVIOUS NEXT
Tagged: #javascript #wait #image #load
ADD COMMENT
Topic
Name
9+5 =