+ 3
How to display any color for text in JS?
I want to color text. What I need to do? Need I start with var? And then what?
3 Antworten
+ 3
html:
<div id="text">Hello</div>
js:
document.getElementById('text').style.color = 'red';
// this would set the text "Hello" in red color
Please complete your css and JavaScript courses in order to understand it.
+ 4
Thanks
+ 3
First, make your tag with the text have an ID. Like this:
<span id="THEID">YOUR TEXT</span>
Then, this code will change the font color to red:
document.getElementById("THEID").style.color = "red" ;
Make sure that the item is loaded before the code executes.
Have fun!