Javascript examples for DOM:Document body
The body property sets or gets the document's body.
It returns the <body> element of the current document.
When setting a new value, this property overwrites all child elements inside the existing <body> element.
document.body returns the <body> element, while the document.documentElement returns the <html> element.
Set the body property with the following Values
Value | Description |
---|---|
newContent | Sets the new content for <body> |
A reference to the Body Object, which represents a <body> element
The following code shows how to change the background color of the current document:
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Test</button> <script> function myFunction() {/*from w w w . j a va 2 s . c o m*/ document.body.style.backgroundColor = "yellow"; } </script> </body> </html>