Welcome to %s forums

<No. 1 Community for developers, by developers/>

Login Register

How to show alternative missing image thumbnail for missing images?

Get support on JavaScript,jQuery, AJAX and other related technology.
Post Reply
admin
Site Admin
Posts: 45

How to show alternative missing image thumbnail for missing images?

Post by admin » Thu Aug 22, 2019 2:51 pm

Code: Select all

// Replace source
$('img').on("error", function() {
  $(this).attr('src', '/images/missing.png');
});
If image has any issue for being loaded then show any placeholder image.

Alternatively, if image is not being loaded then instead of showing missing icon on browser, you can hide the image element.

Code: Select all

// Or, hide them
$("img").on("error", function() {
  $(this).hide();
});

Post Reply