Jethro Ncis
Jethro Ncis

Reputation: 51

Change background color dynamically with JavaScript

In my css a background-color is defined set as white, but I want to change color dynamically body of page.

How do you do that? my CSS file:

body {
    color: #333;
    background-color: #FFF;
}

my javascript code :

function init() 
{
    document.body.style.zoom="90%";
    document.body.color="white";
}

Thank you.

Upvotes: 5

Views: 20491

Answers (2)

Arun P Johny
Arun P Johny

Reputation: 388436

For changing the style you need to access the style property, and the property of background-color is backgroundColor

 document.body.style.backgroundColor="white"

Upvotes: 2

Paritosh
Paritosh

Reputation: 11568

document.body.style.background = 'yourColor';

How do I change the background color with Javascript?

Upvotes: 2

Related Questions