[Javascript] Change the color of a text
Solved
Kopros
Posted messages
631
Status
Member
-
Kopros Posted messages 631 Status Member -
Kopros Posted messages 631 Status Member -
Hello everyone,
I can't find online how to change the color using JavaScript (everything I found doesn't work).
Here's some snippets from my page:
With this code, the text doesn't appear. Yet I perform other actions in the grisett() function that are taken into account.
I'm a beginner in JS so I wouldn't be surprised if I missed something.
At first, I had put the text between the <div> and </div> tags, but everything I've tried to change its color with JS hasn't worked.
So, if you see my mistake or know a simpler way to change the color of my text, thank you for your help.
Configuration: Linux / Firefox 3.5.8
I can't find online how to change the color using JavaScript (everything I found doesn't work).
Here's some snippets from my page:
... function grisett() { document.getElementById('pouet').innerHTML = "<span style='color:red'>my text that should be red</span>"; } ... <body onload="grisett()"> ... <div id="pouet"></div> ... With this code, the text doesn't appear. Yet I perform other actions in the grisett() function that are taken into account.
I'm a beginner in JS so I wouldn't be surprised if I missed something.
At first, I had put the text between the <div> and </div> tags, but everything I've tried to change its color with JS hasn't worked.
So, if you see my mistake or know a simpler way to change the color of my text, thank you for your help.
Configuration: Linux / Firefox 3.5.8
1 answer
In your header (<head> ? </head>) :
--
Your computer doesn't do what you want ... but what you tell it to do.
<script type="text/javascript"> window.onload = function() { document.getElementById('pouet').style.color = '#f00'; }; </script>In your content :<div id="pouet">My text that should be in red</div>
--
Your computer doesn't do what you want ... but what you tell it to do.
Sorry for not responding sooner, I was busy with something else and couldn't test the code before.
A big thank you to you, Avion F16! :)