Looking for ways to set multiple fallbacks for image loading in case the original image source threw an exception.
Given an image tag such as <img id="art"> the following JS code sets a fallback image src to album.jpg when the first image cover.jpg throws an error:
var art = document.getElementById('art');
art.src = "cover.jpg";
art.onerror = () => {
art.src = "album.jpg";
};
How to trigger another onerror handler that will set yet another fallback in case when album.jpg is missing? E.g. if loading cover.jpg fails, and then album.jpg fails too, how to set yet another fallback to e.g. front.jpg and so on?
The same onerror handler will fire multiple times, if the
srcproperty is updated multiple times.