w3resource logo


JavaScript Document Object -  bgColor property

JavaScript Document Object : bgColor property

Secondary Nav

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".

http://www.w3resource.com/javascript/client-object-property-method/document-bgColor.phpVersion

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.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"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

Supported Browser

Internet Explorer 7 Firefox 3.6 Google Chrome 7 Safari 5.0.1 Opera 10
Yes Yes Yes Yes Yes

See also :

JavaScript Client side objects, methods, properties.

JavaScript Core objects, methods, properties.



Is this content useful for you?

 


You might be using Adblocker. Since w3resource does not charge anything from users, all of our expenses (e.g. Hosting, Content Creation, Development etc.) are met by advertisement. Please whitelist w3resource.