+ 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?

15th May 2019, 12:33 PM
Anastasiia Kudria
Anastasiia Kudria - avatar
3 odpowiedzi
+ 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.
15th May 2019, 12:39 PM
Calviղ
Calviղ - avatar
+ 4
Thanks
15th May 2019, 1:06 PM
Anastasiia Kudria
Anastasiia Kudria - avatar
+ 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!
15th May 2019, 12:41 PM
inxanedev!
inxanedev! - avatar