Styles MenuThe BeelineTips & Tricks MenuJavaScript MenuGrouping

JavaScript

Colors

You can change the background color of a document at any time by setting document.bgColor to a new color. However, you cannot change any foreground colors -- fgColor (TEXT), alinkcolor, and so on -- if the page has already been written and is displayed on the screen. To change foreground colors, you need to close the input stream to the document [document.close()], open a new document [document.open()], and rewrite the entire page with new color values in the <BODY> tag set for that page.

Example

This page shows a button that, when clicked, changes the background color of the current page from white to purple or vice versa. Note that the JavaScript if() statement still requires the triplet with a pound sign (#) or stated as '#ffffff' rather than 'white'.

<HTML>
<HEAD>
<SCRIPT LANGUAGE = "JavaScript">
function reversecolor() {
// The if statement still requires the triplet.
if (document.bgColor == '#ffffff') {
document.bgColor = 'purple'}
else {
document.bgColor = 'white'
}
}
</SCRIPT>
<BODY bgColor = 'white'>
<FORM>
<INPUT TYPE = "button" value="click me" onclick="reversecolor()">
</FORM>
</BODY>
</HTML>

Return to JavaScript MenuJavaScript

Click for details.

Click for details.Click for details.

Top of PageTool Bar 1Tool Bar 2Tool Bar 3Tool Bar 4Tool Bar 5Tool Bar 6Tool Bar 7Add RequestChange Request
Styles MenuTool Bar 11Tool Bar 12Tool Bar 13Tool Bar 14Tool Bar 15Tool Bar 16Tool Bar 17KeyholeReport Menu

Home PageMain Text MenuMain Tables MenuMain Frames MenuMain Buttons MenuMain TV MenuMain HiveCD MenuMenu Styles Information


Notice 1

Legal notices - Part 1
Special Notice
Legal notices - Part 2
Notice 2