[ACCEPTED]-How can I reference the <HTML> element's corresponding DOM object?-html

Accepted answer
Score: 46

The <html> element can be referred through the 5 document.documentElement property. In general, the root element 4 of any document can be referred through 3 .documentElement.

document.documentElement.style.background = '';

Note: .style.background returns the value for background as an inline style property. That 2 is, defined using <html style="background:..">. If you want to get the 1 calculated style property, use getComputedStyle:

var style = window.getComputedStyle(document.documentElement);
var bgColor = style.backgroundColor;
Score: 8

The root element (<html>) can be found in document.documentElement, not 2 document.html.

This is because documentElement is standard DOM and not 1 an HTML specific extension.

Score: 0

Why too set the style on the HTML , do use 4 body tag for any styling ..

to change the 3 background applied on html you have to get 2 to the root of the page

using document.documentElement 1 can do

Use this

document.documentElement.style.background = '';

More Related questions