1

How can we set default image in case if original image is not loaded or gives error and shows only alt text in place of image in html

Vijay Dwivedi
  • 172
  • 2
  • 12
  • Does this answer your question? [Inputting a default image in case the src attribute of an html is not valid?](https://stackoverflow.com/questions/980855/inputting-a-default-image-in-case-the-src-attribute-of-an-html-img-is-not-vali) – ArunPratap Feb 05 '20 at 11:44
  • share what you have tried. – Gugan Abu Feb 05 '20 at 11:44

1 Answers1

2

try this way

<img id="currentPhoto" src="SomeImage.jpg" onerror="this.onerror=null; this.src='https://homepages.cae.wisc.edu/~ece533/images/airplane.png'" alt="" width="100" height="120">

Use onerror for this issue

Bhargav Chudasama
  • 6,928
  • 5
  • 21
  • 39