Created
December 6, 2020 02:13
-
-
Save 911992/0b7c0d92351bcaf69ef475fd76615f71 to your computer and use it in GitHub Desktop.
Javascript image load event
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Kode</title> | |
</head> | |
<body> | |
<div id="a"> | |
</div> | |
<script> | |
var _img_el = document.createElement("img"); | |
_img_el.addEventListener("load",function(){ | |
console.log("loaded!"); | |
document.getElementById("a").appendChild(_img_el); | |
}); | |
_img_el.addEventListener("error",function(){ | |
console.log("Error! NO!"); | |
document.getElementById("a").innerHTML= "NOT STONKES!"; | |
}); | |
/* _img_el.src="https://preview.redd.it/mrteoyw94w941.jpg?width=960&crop=smart&auto=webp&s=02389677e41a84631ee0d7769ff988754b7f3a5b"; */ | |
_img_el.src="https://i.kym-cdn.com/entries/icons/original/000/032/379/Screen_Shot_2020-01-09_at_2.22.56_PM.png"; | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment