how to change background image with js code example

Example 1: set attribute javascript background image

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

Example 2: change background with js

document.body.style.backgroundColor = "red";

Example 3: change background with js

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

Example 4: change background with js

document.body.style.backgroundAttachment = "fixed";

Example 5: change background with js

document.getElementById("myDIV").style.background = "url('smiley.gif') blue repeat-x center";