Change color of specific word got from script

I’m trying to adapt a code to change the color of a single word, but I don’t know how.

The original code is

crypt_single_getPar = eval('(' + httpGet("https://api.cryptonator.com/api/ticker/" +
crypt_single_base_currency.match(/.*?(([0-9a-z]+))/i)[1] + "-" + crypt_single_target_currency.match(/.*?(([0-9a-z]+))/i)[1]) + ')');

and

if (crypt_single_getPar.success != false) {
if (crypt_single_getPar.ticker.price > 1)
    crypt_single_price = Math.round(crypt_single_getPar.ticker.price * 100) / 100;
else
    crypt_single_price = crypt_single_getPar.ticker.price

var crypt_single_text_style = '<font style="color:#cc0000;"><b>&darr;</b></font>';

if (crypt_single_getPar.ticker.change >= 0) {
    crypt_single_text_style = '<font style="color:#009900;"><b>&uarr;</b></font>';
}

document.write('
<div class="cryptonatorwidget" style="border-radius:4px;padding:10px;' + crypt_single_style + '">
<div><font style="font-size:90%;">' + crypt_single_base_currency + '</font>
<b>' + crypt_single_price + '</b> ' + crypt_single_target_currency.match(/.*?(([0-9a-z]+))/i)[1] +'
</div>');

The result is all in white. ( I couldn’t post the image due to not having the minimum reputation)

Decred (DCR) [current value] BTC

And I’m trying to change the color like this

Decred (DCR) [current value] [green]BTC[green]

I tried to achieve the result

document.write('
<div class="cryptonatorwidget" style="border-radius:4px;padding:10px;' + crypt_single_style + '">
<div><font style="font-size:90%;">' + crypt_single_base_currency + '</font>
<b>' + crypt_single_price + '</b> ' + <span style="color:#2ED7A2;">' + crypt_single_target_currency.match(/.*?(([0-9a-z]+))/i)[1] + '</span>
</div>');

But then all disappeared in the web page.

Could anyone help me?

Thanks.

PS: Also, someone told me to never use eval in wordpress (in this case, a text widget). How to do it without eval?

Read more here: Change color of specific word got from script

Leave a Reply

Your email address will not be published. Required fields are marked *