Vijay Dwivedi
Vijay Dwivedi

Reputation: 172

How to Set Default Image in Html If the original image is not visible or gives Error

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

Upvotes: 1

Views: 951

Answers (1)

Bhargav Chudasama
Bhargav Chudasama

Reputation: 7165

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

Upvotes: 2

Related Questions