Color text | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Color text

Hello, I'm new at learning Web (Js) and I would need to know how can I change the text's colour? Like from black to orange.

23rd Nov 2017, 12:29 PM
Mihnea-Stefan Bondor
Mihnea-Stefan Bondor - avatar
2 Answers
+ 1
Before to learn change color, you should learn how to set HTML tad and id. Once you have your text with HTML tag and id, you can use document.getElementById to access that DOM element. From the return of the DOM variable, you can access the color selector using style method. For example: to set a text with class name of txt in HTML <p class="txt">Text</p> to access that DOM element, in JavaScript: var txt = document.getElementById('txt'); finally use style method to change the css color: txt.style.color = 'orange';
23rd Nov 2017, 1:07 PM
Calviղ
Calviղ - avatar
+ 1
Thank you Calvin.
23rd Nov 2017, 2:58 PM
Mihnea-Stefan Bondor
Mihnea-Stefan Bondor - avatar