I was just wondering that in the html img tag
<img alt = "default image" src = "image">
is it possible to have a alternate image rather than just text. Or if is it possible to nest the img tag in the alt ""s.
I was just wondering that in the html img tag
<img alt = "default image" src = "image">
is it possible to have a alternate image rather than just text. Or if is it possible to nest the img tag in the alt ""s.
No, you can't put another image in the alt attribute of an <img>
. You can however use the onerror event to load another image using JavaScript, so if the original image doesn't load, a backup can be loaded.
function standby() {
document.getElementById('foo').src = 'https://www.google.com/images/srpr/logo11w.png'
}
<img id="foo" src="notfound.gif" onerror="standby()">
As far as I know, the alt attribute is supposed to have only text, since it is helpful for screen readers to "read" images.
If what you are searching for is a alternate image when the main one fails, you can do so with some JavaScript.
On this question you can see how to use the onError usage: