最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

html - Change background color dynamically with JavaScript - Stack Overflow

programmeradmin3浏览0评论

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.

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.

Share Improve this question edited Jun 26, 2013 at 6:56 Abdul Malik 2,6421 gold badge20 silver badges31 bronze badges asked Jun 26, 2013 at 6:18 Jethro NcisJethro Ncis 511 gold badge1 silver badge4 bronze badges 3
  • document.body.style.color="white" , document.body.style.backgroundColor="black" ? – c.P.u1 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. – CJT3 Commented Jun 26, 2013 at 6:25
  • 1 Bookmark this link . It'll be very helpful for you. – mohkhan Commented Jun 26, 2013 at 6:31
Add a ment  | 

2 Answers 2

Reset to default 2
document.body.style.background = 'yourColor';

How do I change the background color with Javascript?

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

 document.body.style.backgroundColor="white"
发布评论

评论列表(0)

  1. 暂无评论