JavaScript Objects: More on String Methods - The FontColor() Method
(Page 4 of 6 )
To change the color of your text, just use the FontColor() method. We covered Colors a few tutorials back, and you can find a sheet with color codes in that article. Here is how you write the code to change your text color:
<html>
<body>
<script type="text/javascript">
var smash="ARGH! HULK SMASH! HULK SMASH GOOD!!!"
document.write("<p>Look, green text!: " + smash.fontcolor("Green") + "</p>")
</script>
</body>
</html>
This would display the following text:
Look, green text!: ARGH! HULK SMASH! HULK SMASH GOOD!!!
The FontSize() Method
Just as we can change the color of text, we can change the size as well. I know, it's a real shocker. We do this with the FontSize() method:
<html>
<body>
<script type="text/javascript">
var smash="Hulk SMASH!"
document.write("<p>" + smash.fontsize(16) + "</p>")
</script>
</body>
</html>
This prints out:
Hulk SMASH!
Next: FromCharCode() Method >>
More JavaScript Articles
More By James Payne