Tyrone Hirt
Tyrone Hirt

Reputation: 341

How to change color of a piece of text in Javascript?

At first, I apologize for such a basic question, but I'm really new to javascript and I needed to change the color of a script's loading percentage.

The script snippet is this one:

function showProgressMessage(e) {
  $('#progress').removeClass('red-text').html(e);
}

showProgressMessage(fileName + ": Loading: " + Math.floor(100 * cnt / end) + "%");

How do I change the color of Math.floor(100 * cnt / end) + "%"?

Upvotes: 1

Views: 154

Answers (3)

Ahmad Diki
Ahmad Diki

Reputation: 11

you can also use color Hex RGB, Example for green color using #008000

showProgressMessage(fileName + ": Loading: <span style='color: #008000;'>" + Math.floor(100 * cnt / end) + "%</span>");

Upvotes: 1

Challenge Win
Challenge Win

Reputation: 114

I hope this will help you.

showProgressMessage(fileName + ": Loading: <span style='color: blue;'>" + Math.floor(100 * cnt / end) + "%</span>");

Upvotes: 2

Unmitigated
Unmitigated

Reputation: 89507

You can wrap that part of the text inside a <span> that has its CSS color property set.

showProgressMessage(fileName + ": Loading: <span style='color: green;'>" 
                       + Math.floor(100 * cnt / end) + "%</span>");

Upvotes: 2

Related Questions