0 votes
1 view
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

Welcome to Intellipaat Community. Get your technical queries answered by top developers !

Categories

...