5

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.

Abdul Malik
  • 2,632
  • 1
  • 18
  • 31
Jethro Ncis
  • 51
  • 1
  • 1
  • 4
  • `document.body.style.color="white"` , `document.body.style.backgroundColor="black" ` ? – c.P.u1 Jun 26 '13 at 06:22
  • document.body.color is the same as color in css, it applies to text color, not background color. – CJT3 Jun 26 '13 at 06:25
  • 1
    Bookmark this [link](http://www.sitestepper.be/en/css-properties-to-javascript-properties-reference-list.htm) . It'll be very helpful for you. – mohkhan Jun 26 '13 at 06:31

2 Answers2

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

How do I change the background color with Javascript?

Community
  • 1
  • 1
Paritosh
  • 11,144
  • 5
  • 56
  • 74
2

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

 document.body.style.backgroundColor="white"
Arun P Johny
  • 384,651
  • 66
  • 527
  • 531