fontcolor

Causes a string to be displayed in the specified color as if it were in a <FONT COLOR=color> tag.

Applies to

String

Syntax

fontcolor(color)

Parameters

color

A string expressing the color as a hexadecimal RGB triplet or as a string literal. String literals for color names are listed in Appendix B, "Color Values," in the JavaScript Guide.

Description

Use the fontcolor method with the Write method to format and display a string in a document.

If you express color as a hexadecimal RGB triplet, you must use the format rrggbb. For example, the hexadecimal RGB values for salmon are red=FA, green=80, and blue=72, so the RGB triplet for salmon is "FA8072".

The fontcolor method overrides a value set in the fgColor property.

Examples

The following example uses the fontcolor method to change the color of a string:

var worldString="Hello, world"
Console.Write(worldString.fontcolor("maroon") +
      " is maroon in this line")
Console.Write("<P>" + worldString.fontcolor("salmon") +
      " is salmon in this line")
Console.Write("<P>" + worldString.fontcolor("red") +
      " is red in this line")
Console.Write("<P>" + worldString.fontcolor("8000") +
      " is maroon in hexadecimal in this line")
Console.Write("<P>" + worldString.fontcolor("FA8072") +
      " is salmon in hexadecimal in this line")
Console.Write("<P>" + worldString.fontcolor("FF00") +
      " is red in hexadecimal in this line")

The previous example produces the same output as the following HTML:

<FONT COLOR="maroon">Hello, world</FONT> is maroon in this line
<P><FONT COLOR="salmon">Hello, world</FONT> is salmon in this line
<P><FONT COLOR="red">Hello, world</FONT> is red in this line
<FONT COLOR="8000">Hello, world</FONT> 
is maroon in hexadecimal in this line
<P><FONT COLOR="FA8072">Hello, world</FONT> 
is salmon in hexadecimal in this line
<P><FONT COLOR="FF00">Hello, world</FONT>
is red in hexadecimal in this line