So I recently learned how to use jquery to append a paragraph to a div. However, when I want to update the appended paragraph with document.getElementById.innerHTML, it does not appear to work. How do I solve this?
const priceList = document.getElementById("pricebar");
var coinlist = ["BTC", "ETH", "LUNA", "LYXE", "ATOM", "SOL", "AVAX"];
var coinIds = [];
var delayTime = 2000;
const coinNamesAndPrices = document.getElementsByClassName("pricebardata");
const heyyy = document.getElementById("test");
var amountofCalls = 0;
getCoinPrices();
window.setInterval(function() {
amountofCalls += 1;
getCoinPrices();
console.log(amountofCalls);
}, delayTime);
function getCoinPrices(){
var xmlhttp = new XMLHttpRequest();
var coinPrices;
var url = "https://api.nomics.com/v1/currencies/ticker?key=(keyname)=" + coinlist.join();
var jsonData;
xmlhttp.onreadystatechange = function(){
if (this.readyState == 4 && this.status == 200){
var json = JSON.parse(this.responseText);
jsonData = parseJson(json);
}
}
xmlhttp.open("GET", url, true);
xmlhttp.send();
}
function parseJson(json){
var coinIds = [];
var coinPrices = [];
for (i=0; i<coinlist.length; i++){
coinIds.push(String(json[i]["id"]));
coinPrices.push(String(json[i]["price"]));
}
var coinPricesInt = coinPrices.map(Number);
var coinPricesRounded2Decimals = coinPricesInt.map(function roundPrices2Decimals(price){
return price.toFixed(2);
//return Math.round(price * 100)/100
})
if (amountofCalls == 0){
addPriceDataHTML(coinPricesRounded2Decimals, coinIds);
}
else {
console.log(coinPricesRounded2Decimals);
coinNamesAndPrices.innerHTML = coinIds[i] + ":" + " " + "$" + coinPricesRounded2Decimals[i];
}
}
function addPriceDataHTML(coinPriceDollars, coinNames){
for (i=0; i<coinNames.length; i++){
$("#pricebar").append('<p class="pricebardata">' + coinNames[i] + ":" + " " + "$" + coinPriceDollars[i] + '</p>');
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="pricebar">
*appended paragraphs with classnames which I want to edit here*
</div>
Would really appreciate any help I can get! Thanks