The Document.body property represents the <body> or <frameset> node of the current document, or null if no such element exists.
The Document.body property represents the <body> or <frameset> node of the current document, or null if no such element exists.
One of the following:
<body><frameset>nulljs
// Given this HTML: <body id="oldBodyElement"></body> alert(document.body.id); // "oldBodyElement" const aNewBodyElement = document.createElement("body"); aNewBodyElement.id = "newBodyElement"; document.body = aNewBodyElement; alert(document.body.id); // "newBodyElement"
document.body is the element that contains the content for the document. In documents with <body> contents, returns the <body> element, and in frameset documents, this returns the outermost <frameset> element.
Though the body property is settable, setting a new body on a document will effectively remove all the current children of the existing <body> element.
| Specification |
|---|
| HTML Standard # dom-document-body-dev |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
body |
1 | 12 | 60 | 4 | 9.6 | 1 | 4.4 | 18 | 60 | 10.1 | 1 | 1.0 |
© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Document/body