JavaScript Document Object : bgColor property
Description
A string specifying the color of the document background. The bgColor property expressed as HTML hexadecimal triplet value (for example "00FF80) or any standard color name like "red".
Version
Implemented in JavaScript 1.0
Syntax
document.bgColor = "color_name"
Example of document Object : bgColor property
In the following web document bgColor property change the background color of the document.
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /><title>JavaScript document Object : bgColor Property. Example-1</title>
</head>
<body>
<h1 style="color: red">JavaScript document Object : bgColor Property</h1>
<h3>Click on any button and check the background color of the document.</h3>
<hr />
<form action="#">
<input type="button"
value="Red"
name="button1"
onclick="changeBackGroundColor('red')" />
<br />
<input type="button"
value="Blue"
name="button2"
onclick="changeBackGroundColor('blue')" />
<br />
<input type="button"
value="White"
name="button3"
onclick="changeBackGroundColor('white')" />
</form>
<script type="text/javascript" language="JavaScript">
//This is done to make the following JavaScript code compatible to XHTML. <![CDATA[
// Following function changes the background color and fills in the text box.
function changeBackGroundColor(color)
{
document.bgColor=color;
}
//]]>
</script>
</body>
</html>
View the example of document object's bgColor property in the browser
Practice document object's bgColor property with Online Editor
Supported Browser
| Internet Explorer 7 | Firefox 3.6 | Google Chrome 7 | Safari 5.0.1 | Opera 10 |
| Yes | Yes | Yes | Yes | Yes |
See also :
Please Google+, Like this tutorial on FaceBook, Tweet, save it as bookmark and subscribe with our Feed. Have suggestions? comment using Disqus down this page. Thanks.





