JavaScript fontcolor()Method

String 对象参考手册JavaScript String Object

Definition and Usage

The fontcolor() method is used to display a string in the specified color.

This method returns a string wrapped in a <font> tag, as shown below:

<font color="colorvalue">string</font>

Syntax

string.fontcolor(color)

Parameters Description
color Required. Specifies the font-color for the string. The value must be a color name (red), an RGB value (rgb(255,0,0)), or a hexadecimal number (#FF0000).


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the fontcolor() method.


Example

Example

Display a string in green:

<script>

var str = "Hello world!";
document.write(str.fontcolor("green"));

</script>

Try it yourself »


String 对象参考手册JavaScript String Object Other Extensions