English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
InBodyThe property sets or returns the main element of the document.
This property returns the elements of the current document.
Setting new text on the document will effectively delete all current children of the existing elements.
Please refer todocument.documentElementProperty, which returns the root (<html>) element.
Return the body property:
document.body
Set the body property:
document.body = content
document.body.style.background = "coral";Test and see‹/›
All browsers fully support the body property:
Property | |||||
body | Is | Is | Is | Is | Is |
Value | Description |
---|---|
content | The document.body property uses a single valueContent,which is used to add new content to the body element |
Return Value: | Reference to the Body object, which represents an element |
---|---|
DOM Version: | DOM Level1 |
Change the HTML content of the current document:
document.body.innerHTML = "<h1>Hello world</h1>";Test and see‹/›