0

Please help. I have been coding my Website. And I have tried to make the text for my website red, but only a certain part using Javascript.

document.getElementById("derping").innerHTML = "You have: " + derp + " Derple Points"; 

I want to make "derp" Red. I tried:

document.getElementById("derping").innerHTML = "You have: " + derp.fontcolor("red") + " Derple Points"; 

But that doesn't seem to work. Can anyone help?

Thanks, Jackson.

0

1 Answer 1

1

You can change an element's font color after it was created, for example:

document.body.style.color = 'red'; 

However, in your case, I'd suggest having a class .red and wrapping your text with a span of this class:

document.getElementById("derping").innerHTML = "You have: <span class='red'>" + derp + "</span> Derple Points"; 

And in your css:

.red{ color: red; } 

If you don't want to change your css:

document.getElementById("derping").innerHTML = "You have: <span style='color:red'>" + derp + "</span> Derple Points"; 
Sign up to request clarification or add additional context in comments.

2 Comments

Sadly, I can't use CSS... (It's because of various problems...I'll try uploading css...), Thanks Though.
@Mario1luigi9 Ok, then, try the 3rd solution I provided.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.