Javascript Reference - HTML DOM Body Object








The Body object represents an HTML <body> element.

Standard Properties and Events

The Body object supports the standard properties and events.

Example

We can access a <body> element by using getElementsByTagName().


<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">test</button>
<!--from   w w  w . ja v  a 2 s .c  o  m-->
<p id="demo"></p>

<script>
function myFunction() {
    var x = document.getElementsByTagName("BODY")[0];
    x.style.backgroundColor = "red";
}
</script>

</body>
</html>

The code above is rendered as follows:





Body Object Properties

Property Description
aLink Not supported in HTML5. See CSS :active Selector instead.
Sets or gets the color of an active link
background Not supported in HTML5. Use style.backgroundImage instead.
Sets or gets the background image
bgColor Not supported in HTML5. Use style.backgroundColor instead.
Sets or gets the background color
link Not supported in HTML5. See CSS :link Selector instead.
Sets or gets the color of unvisited links
text Not supported in HTML5. Use style.color instead.
Sets or gets the color of the text
vLink Not supported in HTML5. See CSS :visited Selector instead.
Sets or gets the color of visited links