How to set background image url = variable

Hi! I’m trying to change a background image by using a variable. Is this possible?

const picture_url = https://upload.wikimedia.org/wikipedia/commons/thumb/9/97/The_Earth_seen_from_Apollo_17.jpg/599px-The_Earth_seen_from_Apollo_17.jpg;

document.style.backgroundImage = "url(’${picture_url}’ ) ";

you can do this by using the following syntax :

document.body.style.cssText+=`background-image:url(${image_url})`;

I applied background image to the body .you can select any element you want to set background-image.

Thanks a lot. I’ve never seen cssText before, will use it from now :slight_smile: