How can I reference the <HTML> element's corresponding DOM object?

后端 未结 3 1996
名媛妹妹
名媛妹妹 2020-12-10 01:22

This is how you access the element to set a background style:

document.body.style.background = \'\';

But how can

3条回答
  •  北海茫月
    2020-12-10 01:59

    The element can be referred through the document.documentElement property. In general, the root element of any document can be referred through .documentElement.

    document.documentElement.style.background = '';
    

    Note: .style.background returns the value for background as an inline style property. That is, defined using . If you want to get the calculated style property, use getComputedStyle:

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

提交回复
热议问题