Change a text color on click

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
fastfingertips
Forum Contributor
Posts: 242
Joined: Sun Dec 28, 2003 1:40 am
Contact:

Change a text color on click

Post 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?
jollyjumper
Forum Contributor
Posts: 107
Joined: Sat Jan 25, 2003 11:03 am

Post 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.
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

Code: Select all

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