Goodmorning everyone,
I am currently having some issues with my jQuery code. I am trying to use the CoinMarketCap API at cryptokickoff to display cryptocurrencies their stats on my site. I know how to display them but the appending to my columns is not working right.
What I'm trying to do: - I give an array which cointains the crypto's I want to display from the API - I want to append each crypto to a row, which starts at 0 (var i) and goes up by one for every crypto
Now what's happening is that all the crypto's are put into the row with id crypto-3 and I have no idea how that is happening.
Any help would be highly appreciated!
function fillGrid() {
var cryptos = ["bitcoin","ethereum","ripple"];
var i = 0;
jQuery(cryptos).each(function(){
jQuery.get( "https://api.coinmarketcap.com/v1/ticker/"+cryptos[i]+"/", function( data ) {
jQuery("#crypto-"+i).append(
data[0].name);
});
i++;
})
};
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/css/bootstrap.min.css" integrity="sha384-Zug+QiDoJOrZ5t4lssLdxGhVrurbmBWopoEl+M6BdEfwnCJZtKxi1KgxUyJq13dy" crossorigin="anonymous">
<script src="http://code.jquery.com/jquery-latest.min.js"
type="text/javascript"></script>
<script src="api.js" type="text/javascript"></script>
</head>
<body>
<div class="container-fluid">
<div class="row">
<div class="col-sm-12 col-md-6 col-lg-4" id="crypto-0">
</div>
<div class="col-sm-12 col-md-6 col-lg-4" id="crypto-1">
</div>
<div class="col-sm-12 col-md-6 col-lg-4" id="crypto-2">
</div>
</div>
<div class="row">
<div class="col-sm-12 col-md-6 col-lg-4" id="crypto-3">
</div>
<div class="col-sm-12 col-md-6 col-lg-4" id="crypto-4">
</div>
<div class="col-sm-12 col-md-6 col-lg-4" id="crypto-5">
</div>
</div>
</div>
<script type="text/javascript">
fillGrid();
</script>
</body>
</html>