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

javascript - Fastest way to change page background color using JS? - Stack Overflow

programmeradmin1浏览0评论

What's the smallest and fastest way to modify a document's background color using javascript? it should be cross browser.

I tried the following which didn't work in firebug:

   document.body.bgcolor = "#eee";

   document.documentElement.bgcolor = "#eee";

What's the smallest and fastest way to modify a document's background color using javascript? it should be cross browser.

I tried the following which didn't work in firebug:

   document.body.bgcolor = "#eee";

   document.documentElement.bgcolor = "#eee";
Share Improve this question asked Feb 24, 2011 at 12:32 Robin RodricksRobin Rodricks 114k147 gold badges414 silver badges617 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 9

Use the backgroundColor CSS property:

document.body.style.backgroundColor = "#eeeeee";

This should work:

document.body.style.backgroundColor = "#eee";

Here is a live demo.

发布评论

评论列表(0)

  1. 暂无评论