Document: body property - Web APIs | MDN (original) (raw)
Baseline Widely available
The Document.body
property represents the or node of the current document, ornull
if no such element exists.
Value
Examples
// 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"
Notes
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.
Specifications
Specification |
---|
HTML Standard # dom-document-body-dev |
Browser compatibility
BCD tables only load in the browser