JavaScript fontcolor method
The fontcolor method returns a string with color defined using the color attribute in the HTML font tag. The syntax is as follows:
The code copy is as follows:
str_object.fontcolor( color )
Parameter description:
| parameter | illustrate |
|---|---|
| str_object | String (object) to operate |
| color | Required. Color name (red), RGB value (rgb(255,0,0)) or hexadecimal number (#FF0000) |
Tip: This method does not comply with ECMA standards and is not recommended for use.
fontcolor method example
The code copy is as follows:
<script language="JavaScript">
var str = "www.VeVB.COM";
document.write( str.fontcolor("red") );
</script>
Run this example and output:
The code copy is as follows:
www.VeVB.COM
Tip: This method returns a string defined using the HTML color tag, that is, using this method cannot dynamically change the color of the font. If you want to dynamically change the font color of the element, you can refer to the following example:
Further reading: Change the font color of page elements
The code copy is as follows:
<html>
<script language="JavaScript">
function changFont( x ){
var font_style = x;
var article = document.getElementById("article");
if( typeof font_style == "string" ){
article.style.color = font_style;
}
}
</script>
<body>
<p>
<a onClick="changFont('black');">Black</a> <a onClick="changFont('red');">Red</a>
<a onClick="changFont('blue');">Blue</a>
</p>
<p id="article">
I'm some text...<br />
Some Text ...
</p>
</body>
</html>
In this example, the color of the font (id="article") can be dynamically changed through JavaScript.