1

How to tell if the image is loading failure (404 not found, or other 4xx or 5xx erros) in a html img tag and report by a jquery callback?

Abby Chau Yu Hoi
  • 1,378
  • 3
  • 15
  • 37

1 Answers1

3
$('img').error(function(){
    //...
});

Docs

An example from the docs:

<img alt="Book" id="book" />

$('#book')
  .error(function() {
    alert('Handler for .error() called.')
  })
  .attr("src", "missing.png");
gdoron
  • 147,333
  • 58
  • 291
  • 367