Document.body - Web APIs 编辑
The Document.body
property represents the <body>
or <frameset>
node of the current document, or null
if no such element exists.
Syntax
const objRef = document.body document.body = objRef
Example
// 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 | 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 |
Browser compatibility
BCD tables only load in the browser
See also
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论