We're looking for a user researcher to understand the needs of developers and designers. Is this you or someone you know? Check out the post: https://mzl.la/2IGzdXS

document.body Redirect 1

Returns the <body> or <frameset> node of the current document, or null if no such element exists.


var objRef = document.body; 
document.body = objRef;


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

var 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 body is settable, setting a new body on a document will effectively remove all the current children of the existing <body> element.


Document Tags and Contributors

Last updated by: Sheppy,