Change the background color of the current document:
More "Try it Yourself" examples below.
The body property sets or returns the document's body.
On return, this property returns the <body> element of the current document.
On set, this property overwrites all child elements inside the existing <body> element, and replaces it with the new, specified content.
Property | |||||
---|---|---|---|---|---|
body | Yes | Yes | Yes | Yes | Yes |
Return the body property:
Set the body property:
Value | Description |
---|---|
newContent | Specifies the new content for <body> |
Return Value: | A reference to the Body Object, which represents a <body> element, or null if the element does not exist |
---|---|
DOM Version | Core Level 1 Document Object |
Get the HTML content of the current document:
Change the HTML content of the current document (will overwrite all existing HTML elements inside <body>):
Create a <p> element with some text and append it to the document's body:
HTML reference: HTML <body> tag
JavaScript reference: HTML DOM Body Object