HTML DOM bodyProperty
Examples
Change the background color of the current document:
Try it Yourself »
Definition and Usage
The body property is used to set or return the document body.
When returning, this property returns the current document's<body>element.
When setting, this property overwrites all child elements in the <body> element and replaces them with new content.
Tip:anddocument.documentElementThe difference between the properties is that the document.body property returns the <body> element, while the document.documentElement property returns the <html> element.
Browser Support
| Property | |||||
|---|---|---|---|---|---|
| body | Yes | Yes | Yes | Yes | Yes |
Syntax
Return the body property:
document.body
Set the body property:
document.body = newContent
Property
| Value | Description |
|---|---|
| newContent | Specifies the new content of the <body> |
Technical Details
| DOM Version: | Core Level 1 Document Object |
|---|---|
| Return Value: | A reference to the Body object, representing the <body> element |
More Examples
Example
Get the HTML content of the current document:
Try it Yourself »
Example
Modify the HTML content of the current document:
Try it Yourself »
Example
Create a <p> element and add it to the document:
Try it Yourself »
Related Pages
HTML Reference Manual:HTML <body> Tag
JavaScript Reference Manual:HTML DOM Body Object
Other Extensions
Document Object