Document.body 속성은 현재 문서의 <body> 혹은 <frameset> 노드를 나타냅니다. 일치하는 요소가 존재하지 않으면 null을 반환합니다.

예제

// HTML: <body id="oldBodyElement"></body>
alert(document.body.id); // "oldBodyElement"

let aNewBodyElement = document.createElement("body");

aNewBodyElement.id = "newBodyElement";
document.body = aNewBodyElement;
alert(document.body.id); // "newBodyElement"

참고

Document.body는 문서에서 사용하는 콘텐츠를 수용하는 요소입니다. <body> 콘텐츠를 가지고 있는 문서는 <body> 요소를 리턴하고, 프레임셋을 가지고 있는 문서는 가장 바깥쪽의 <frameset> 요소를 반환합니다.

body 속성에 새로운 값을 설정할 수 있긴 하지만, 현재 <body> 요소의 모든 자식은 제거됩니다.

명세

Specification Status Comment
HTML Living Standard
The definition of 'Document.body' in that specification.
Living Standard  
HTML 5.1
The definition of 'Document.body' in that specification.
Recommendation  
HTML5
The definition of 'Document.body' in that specification.
Recommendation  
Document Object Model (DOM) Level 2 HTML Specification
The definition of 'Document.body' in that specification.
Obsolete  
Document Object Model (DOM) Level 1 Specification
The definition of 'Document.body' in that specification.
Obsolete Initial definition.

브라우저 호환성 

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidiOS SafariSamsung Internet
Basic supportChrome Full support 1Edge Full support YesFirefox Full support 2
Notes
Full support 2
Notes
Notes The body property was implemented on the HTMLDocument interface in Firefox for a long time, hence document.body would not return the <body> element if the document's Content-Type was not set to text/html or application/xhtml+xml (or if it came from DOMParser.parseFromString without the text/html type being used). This has been fixed in Firefox 60.
IE Full support 6Opera Full support 9.6Safari Full support 4WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support Yes
Notes
Full support Yes
Notes
Notes The body property was implemented on the HTMLDocument interface in Firefox for a long time, hence document.body would not return the <body> element if the document's Content-Type was not set to text/html or application/xhtml+xml (or if it came from DOMParser.parseFromString without the text/html type being used). This has been fixed in Firefox 60.
Opera Android Full support YesSafari iOS Full support 5Samsung Internet Android ?

Legend

Full support  
Full support
Compatibility unknown  
Compatibility unknown
See implementation notes.
See implementation notes.

같이 보기

문서 태그 및 공헌자

이 페이지의 공헌자: urty5656, hoony, fscholz, khalid32, teoli, pusanbear
최종 변경자: urty5656,