Page 1 of 1

Change a text color on click

Posted: Sun Jan 11, 2004 2:15 pm
by fastfingertips
I would like that if i'm clicking on a button to change the color of a text, how can i do that?

Posted: Sun Jan 11, 2004 4:10 pm
by jollyjumper
Hi FastFingertips,

try this:

Code: Select all

<span id="texttochangecolor" style="color:#000000;">
This is a black text. When you click the button it will turn red.
</span>
<input type="button" value="Change color" onclick="document.getElementById('texttochangecolor').style.color='#FF0000';">

Greetz Jolly.

Posted: Sun Jan 11, 2004 5:35 pm
by Gen-ik

Code: Select all

<div style="color:#000000" onclick="this.style.color='#ff0000'>Click to change</div>