The Body object represents an HTML <body> element and can be retrieve using by document method getElementByTagName(). It can be created by using document method createElement().
1 <!DOCTYPE html>
2 <html>
3 <body>
4 <h1>The Body Object</h1>
5 <h2>Example</h2>
6
7 <div class="container">
8 Click button to access body object
9 </div>
10
11 <button onclick="handler()">Access</button>
12
13 <script>
14 function handler() {
15 const element = document.getElementsByTagName("BODY")[0];
16 element.style.backgroundColor = "lightblue";
17 }
18 </script>
19 </body>
20 </html>
Body object
Body object properties
1. | aLink : It used to set and retrieve the the color of an active link in a document, Instead use - CSS :active Selector |
2. | background : It used to set and retrieve the background image for the document, Instead use - style.backgroundImage. |
3. | bgColor : It used to set and retrieve the background color of a document, Instead use - style.backgroundColor. |
4. | link : It used to set and retrieve the color of unvisited links in a document, Instead use -CSS :link Selector. |
5. | text : It used to set and retrieve color of the text in a document, Instead use - style.color. |
6. | vLink : It used to set and retrieve the color of the visited links in a document,Instead use - CSS :visited Selector. |
Note : The above properties does not supported in HTML5
Standard Properties and Events for Body object
The Element object represents an HTML element that can be P, DIV, A, TABLE, or any other HTML element. It provides many methods and properties that can be used to retrieve information and perform operation on element.
The JavaScript provides many Events object that are inherited from Event object and provides specific types of event object.
Related options for your search