Ken Ward's New Java Script Tutorial

This page demonstrates how to change the colour of text on a page


In the last lesson we had java script changing the background colour of the document. Not surprisingly, in this one, we have it changing the text. Try clicking the boxes to see what happens. The code below still works in modern browsers, but a new page shows how to change fgColor using JavaScript and style.

 

 

This is extremely easy because all we do is change the 'b' in bgColor to an 'f'! So the one line of code (for each colour) is:

document.fgColor="red";

And this changes the text in the document to, er, red!

The rest of the code is more or less the same as before with bgColor replaced with fgColor.

We have done a lot of clicking, so let's take a rest and do on mouse over code!


[If you need to learn more about HTML visit the HTML Tutorial]

I am always pleased to hear from you.
Send your comments to