style.backgroundColor (Property)

A color of the styled object's background.

Availability:

CSS level - 1
DOM level - 2
JavaScript - 1.5
JScript - 3.0
Internet Explorer - 4.0
Netscape - 6.0
Opera - 5.0
Property/method value type:String primitive
JavaScript syntax:-myStyle.backgroundColor
CSS syntax:background-color: acolor
HTML syntax:<BODY BGCOLOR="...">
Argument list:acolorA valid color specifier

This background color is applied to the element before any background image is drawn. You can define both a background image and a background color. If you do, and if the background image contains any pixels that are set to a transparent color, then the background color will show through.

There are several ways in which you can access the background color of a document or element. Depending on how you do this, you may affect the entire document or just a part of it.

Example code:

   <HTML>

   <HEAD>

   </HEAD>

   <BODY>

   <DIV ID="ONE" STYLE="background-color:RED">

   The DIV block ONE

   </DIV>

   <DIV ID="TWO" STYLE="background-color:BLUE">

   The DIV block TWO

   </DIV>

   <FORM>

   <INPUT TYPE="button" VALUE="CLICK ME" onClick="clickMe()">

   </FORM>

   <SCRIPT>

   function clickMe()

   {

      myStyle1 = document.all.ONE.style.backgroundColor;

      myStyle2 = document.all.TWO.style.backgroundColor;

   

      document.all.ONE.style.backgroundColor = myStyle2;

      document.all.TWO.style.backgroundColor = myStyle1;

   }

   </SCRIPT>

   </BODY>

   </HTML>

See also:color names, color value, Document.bgColor, JSSTag.backgroundColor, rgb(), style.background