Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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) + "%"?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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>");
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading