<!DOCTYPE html>
<html>
<body>

<p>This example uses the addEventListener() method to attach a "error" event to an img element.</p>

<img id="myImg" src="image.gif">

<p id="demo"></p>

<script>
document.getElementById("myImg").addEventListener("error", myFunction);

function myFunction() {
    document.getElementById("demo").innerHTML = "The image could not be loaded.";
}
</script>

</body>
</html>