I want to set an image as a background, however the image name might be either bg.png or bg.jpg.
Is there any non-javascript way to create
You can have background image with css and use the same image URL in a hidden image tag and onError, change the image URL and make it show it
{
e.currentTarget.src = brokenImageFallbackUrl;
e.currentTarget.style.display = "block";
// or keep this image hidden and set the backgroundImage of the parent div
}}
/>