I'm working on a wordpress website where I'm trying to create a table with real-time cryptocurrency prices and price changes. I am using the coinmarketcap v2 api (https://coinmarketcap.com/api/) to fetch the real time values. Im using a Wordpress plugin (shortcoder) that I can use to shortcode pieces of script.
What I want to do is to style the 24h change percentage value based on whether its value is negative or positive. I have tried both ways of styling seperately and they work.
However, what I cant get to work is the if/else statement in the jQuery to determine whether the 24h change percentage is negative. The jquery script I've tried to create is:
(function($){
$.getJSON('https://api.coinmarketcap.com/v2/ticker/1/', function( data ){
if(data['data']['quotes']['USD']['percent_change_24h']>=0){
$('#btc_24h').html('<span style="color:green;"> '+data['data']['quotes']['USD']['percent_change_24h']+'%</span>');
}else{
$('#btc_24h').html('<span style="color:red;"> '+data['data']['quotes']['USD']['percent_change_24h']+'%</span>');
});
Unfortunately I am not that much of a jQuery hero and I've been trying to figure the problem out all morning. Does anyone know what I might be doing wrong?...
When I delete the if/else statement and just try both types of styling seperately they both work fine...
Aucun commentaire:
Enregistrer un commentaire