// Given this HTML: <body id="oldBodyElement"></body>
alert(document.body.id); // "oldBodyElement"
const newBodyElement = document.createElement("body");
newBodyElement.id = "newBodyElement";
document.body = newBodyElement;
alert(document.body.id); // "newBodyElement"Document: body property / notebook
Document: body property
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.