Fastest way to change page background color using JS?

What is the smallest and fastest way to change the background color of a document using javascript? it must be a cross browser.

I tried the following which did not work in firebug:

   document.body.bgcolor = "#eee";

   document.documentElement.bgcolor = "#eee";
+3
source share
2 answers

Use the backgroundColorCSS property :

document.body.style.backgroundColor = "#eeeeee";
+9
source

This should work:

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

Here is a live demonstration.

+1
source

Source: https://habr.com/ru/post/1794426/


All Articles