Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (9.5k points)

Can anyone tell me a simple method to swap the background color of a webpage with JavaScript? 

1 Answer

0 votes
by (19.7k points)

To do that, you have to modify the JavaScript property document.body.style.background like below: 

function changeBackground(color) {

   document.body.style.background = color;

}

window.addEventListener("load",function() { changeBackground('red') });

Interested in Java? Check out this Java Certification by Intellipaat.    

Related questions

Browse Categories

...