Document.documentElement
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015년 7월.
Document.documentElement ���기 전용 속성은 문서의 루트 요소를 나타내는 Element를 반환합니다. HTML 문서를 예로 들면 <html> 요소를 반환합니다.
구문
js
const element = document.documentElement;
예제
js
const rootElement = document.documentElement;
const firstTier = rootElement.childNodes;
// firstTier is a NodeList of the direct children of the root element
// such as <head> and <body>
for (const child of firstTier) {
// do something with each direct child of the root element
}
참고
모든 비어있지 않은 HTML 문서의 documentElement는 항상 <html> 요소를 가리킵니다. 모든 비어있지 않은 XML 문서의 documentElement는 종류불문하고 해당 문서의 루트 요소를 가리킵니다.
명세
| Specification |
|---|
| DOM # ref-for-dom-document-documentelement① |