I am trying to set a background image with two alternatives. Below is the code I have been using:
<a id="test" style="background: url('image1.png'), background: url('image2.png');">test</a>
My goal is to prioritize the first image (image1.png) and if it does not exist, then set the second image (image2.png). However, currently, when both images exist, both are being set on the a tag...
I would like to only set the first image if it exists, and only set the second image if the first one is missing.
Can someone please advise me on how to solve this issue?
If there is no direct solution, is there a way to handle this through a jQuery event? I attempted to catch an error using the following code, but was unsuccessful:
$("[id='test']").error(function() {
alert( "Handler for .error() called." )
});