A guide on changing webpage background image using JavaScript code

When you want to change a webpage background image using JavaScript, you can do so by setting the background image of the document object model (DOM) property.

The property you need to manipulate for changing the background image of the whole page is document.body.style.backgroundImage:

document.body.style.backgroundImage = "url('image.png')";

You need to put the relative path to the image from your web page’s folder. If the image is located in the same folder, then you can reference it directly inside the url() function as in the code above.

#javascript #web-development

How to Change Webpage Background Image with JavaScript
10.70 GEEK