Seeking a solution to establish multiple fallbacks for image loading in the event that the original image source encounters an exception.
If we have an image tag like <img id="art">
, this JS code will set a fallback image src to album.jpg
when the initial image cover.jpg
results in an error:
var art = document.getElementById('art');
art.src = "cover.jpg";
art.onerror = () => {
art.src = "album.jpg";
};
How can we activate an additional onerror
handler to establish another fallback option if album.jpg
is not found? For example, if the loading of cover.jpg
fails, followed by the failure of album.jpg
, how do we then set up another fallback to something like front.jpg
and so forth?