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.

3
  • document.body.style.color="white" , document.body.style.backgroundColor="black" ? Commented Jun 26, 2013 at 6:22
  • document.body.color is the same as color in css, it applies to text color, not background color. Commented Jun 26, 2013 at 6:25
  • 1
    Bookmark this link . It'll be very helpful for you. Commented Jun 26, 2013 at 6:31

2 Answers 2

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

How do I change the background color with Javascript?

Sign up to request clarification or add additional context in comments.

Comments

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"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.