JavaScript FontColor Method
The FontColor method returns a colored string that is defined using the Color property in the HTML font label. The syntax is as follows:
Copy Code code as follows:
Str_object.fontcolor (color)
Parameter description:
Parameters |
Description |
Str_object |
The string to manipulate (object) |
Color |
Necessary. Color name (red), RGB value (RGB (255,0,0)), or hexadecimal number (#FF0000) |
Tip: This method does not conform to the ECMA standard and is not recommended for use.
FontColor Method Instance
Copy Code code as follows:
<script language= "JavaScript" >
var str = "Www.jb51.net";
document.write (Str.fontcolor ("Red"));
</script>
Run the example and output:
Copy Code code as follows:
Tip: This method returns the string defined using the HTML color label, which means that the method does not dynamically change the color of the font. If you want to change the element font color dynamically, refer to the following example:
Extended reading: Changing page element Font Color
Copy Code code as follows:
<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 am some words ... <br/>
Some Text ...
</p>
</body>
In this example, you can dynamically change the color of the font (id= "article") by using JavaScript to control the way the font CSS is styled.