
- HTML Tutorial
- HTML - Home
- HTML - Overview
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Comments
- HTML - Images
- HTML - Tables
- HTML - Lists
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Frames
- HTML - Iframes
- HTML - Blocks
- HTML - Backgrounds
- HTML - Colors
- HTML - Fonts
- HTML - Forms
- HTML - Embed Multimedia
- HTML - Marquees
- HTML - Header
- HTML - Style Sheet
- HTML - Javascript
- HTML - Layouts
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- HTML - Fonts Ref
- HTML - Events Ref
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
HTML DOM Body property
The HTML DOM body property associated with HTML <body> element is used to set or return property values of the <body> element. It returns the <body> element. It can be used to change content inside the <body> element. This property can overwrite child elements content present inside the <body> element.
Syntax
Following is the syntax for −
Setting the body property −
document.body = New_Content
Here, New_Content is the new content for the element.
Example
Let us see an example for the HTML DOM Body property −
<!DOCTYPE html> <html> <body> <h2>Sample HEADING</h2> <p>Click the below button to overwrite child content</p> <button onclick="OverWrite()">Overwrite Content</button> <p>A sample paragraph</p> <script> function OverWrite() { document.body.innerHTML = "All the content inside the body tag is overwritten"; } </script> </body> </html>
Output
This will produce the following output −
On clicking “Overwrite Content” −
In the above example −
We have various elements inside the <body> element like a <h2> element, two <p> elements and a button. The “Overwrite Content” button executes the OverWrite() function.
<button>Overwrite Content</button>
The OverWrite() function gets the innerHtml of the document body and changes the text to “All the content inside the body tag is overwritten” . This overwrites all the content inside body basically removing all the elements and letting only the text display.
function OverWrite() { document.body.innerHTML = "All the content inside the body tag is overwritten"; }
- Related Articles
- HTML DOM Body object
- HTML DOM tagName Property
- HTML DOM name Property
- HTML DOM nextElementSibling Property
- HTML DOM nextSibling Property
- HTML DOM nodeName Property
- HTML DOM nodeType Property
- HTML DOM nodeValue Property
- HTML DOM offsetHeight Property
- HTML DOM offsetLeft Property
- HTML DOM offsetParent Property
- HTML DOM offsetTop Property
- HTML DOM offsetWidth Property
- HTML DOM textContent Property
- HTML DOM title Property
