I have an HTML img element like this:
<img src="https://theposterdb.com/api/assets/11949" />
And a CSS class like this:
div {
background-image: url(https://theposterdb.com/api/assets/11949);
}
Both of these work and display the image on my site. However when I try to do the following in JavaScript:
fetch("https://theposterdb.com/api/assets/11949")
I get a CORS error. Why? I need to fetch the image in JS because I want to check if it was successfully loaded and otherwise display a custom alternative element.