How can i recreate the following code in pure JavaScript?
$('#img').on('load error', function() { something(); });
How can i recreate the following code in pure JavaScript?
$('#img').on('load error', function() { something(); });
Try this:
<img id="image" src="image.gif" onerror="myFunction()">
Or inline:
document.getElementById("image").addEventListener("error", function(){ something(); });
document.getElementById("image").src = filename;
Or from scratch:
var img=new Image();
img.onload=function(e) { somethingGood(); };
img.onerror=function(e) { somethingBad(); };
img.src=URL;