Anders Anders - 4 months ago 5x
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?


Modify the JavaScript property

For example:

function changeBackground(color) { = 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.