Javascript - String fontcolor() Method

The fontcolor() method can display a string in a specified color.

Description

The fontcolor() method can display a string in a specified color.

This method returns the string embedded in the <font> tag, like this:

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

Syntax

string.fontcolor("color")

Parameter Values

Parameter Require Description
color Required.A color value. The value can be a color name (e.g. red), an RGB value (e.g. rgb(255,0,0)), or a hex number (e.g. #FF0000)e

Return

A string embedded in the <font> tag

Display the text in green color:

Demo

//display a string in a specified color.
var str = "Hello World!";
var result = str.fontcolor("green");
console.log(result);/*w w  w. j a va  2  s  . co m*/

Result