Anders Anders - 5 months ago 10
CSS Question

How do I change the background color with JavaScript?

Anyone know a simple method to swap the background color of a webpage using JavaScript?

Answer

Modify the JavaScript property document.body.style.background.

For example:

function changeBackground(color) {
   document.body.style.background = color;
}

<BODY onload="changeBackground('red');">

This is pure JavaScript, nothing to do with AJAX :)

Note: this does depend a bit on how your page is put together, for example if you're using a DIV container with a different background colour you will need to modify the background colour of that instead of the document body.