provola provola - 1 year ago 63
Javascript Question

Jquery .error method replacement

$(this).attr('src', 'missing.png');

// Or, hide them

This code does'nt work because .error has been removed in jquery 3.x.
What Jquery method or Javascript method can I use to test for broken image?

Answer Source

Use on:

$('img').on("error", function(){
        $(this).attr('src', 'missing.png');

See the jQuery 3 migration guide.