| Availability: |
| ||||||||
| Property/method value type: | String primitive | ||||||||
| JavaScript syntax: | - | myStyle.backgroundColor | |||||||
| CSS syntax: | background-color: acolor | ||||||||
| HTML syntax: | <BODY BGCOLOR="..."> | ||||||||
| Argument list: | acolor | A 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.
<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>| Prev | Home | Next |
| style.backgroundAttachment | Up | style.backgroundImage |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. | ||