JavaScript tutorial:
fontcolor method

 

Applies to: String Object

The fontcolor method places an HTML <FONT> tag with the COLOR attribute around the text in a String object.

Syntax

strVariable.fontcolor(colorval)
"String Literal".fontcolor(colorval)

The colorval argument is a string containing a color value. This can either be the hexadecimal value for a color, or the predefined name for a color.

Return value

None

Example

The following example demonstrates the fontcolor method:

<HEAD>
<SCRIPT LANGUAGE="JavaScript">
function FontColorTag()
{
var strVariable = "This is a test";
strVariable = strVariable.fontcolor("blue");
return strVariable
}
</SCRIPT></HEAD>
<BODY>
<P> See how it work in Html
<SCRIPT LANGUAGE="JavaScript"> document.write(FontColorTag());</SCRIPT> </P>
</BODY>

Valid predefined color names depend on your JavaScript host (browser, server, and so forth). They may also vary from version to version of your host. Check your host documentation for more information.

To run the code, paste it into JavaScript Editor, save as htm file format and click the Show Internal View button.

See also: fontsize method, String Object methods, String Object Properties