Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change colour of text when using document.getElementById("id").innerHTML

I am trying to change the text of a span to something else when a particular event occurs. I am doing this as :

document.getElementById("usernameError").innerHTML = "**Message";

I want to display the same in a different colour. Any idea on how to do that? Much appreciated!

like image 425
TheLuminor Avatar asked Jul 30 '15 08:07

TheLuminor


People also ask

How do you color text in JavaScript?

Use the String fontcolor() Method We can apply the fontcolor() method on any text string, and it returns the <font> HTML element with the color attribute.


1 Answers

You could always just put the message in a span and put a style attribute on it. This should do it:

document.getElementById("usernameError").innerHTML = "<span style='color: red;'>**Message</span>";
like image 192
Eric Bulloch Avatar answered Oct 19 '22 04:10

Eric Bulloch