I have a problem that I don´t know how to solve. The script below displays stocks and its current value. One thing i want to add is the color green if the stock has a positive value and red if the stock has a negative value.
How can change the color of the div "value" for each row depending on the current value?
$(document).ready(function stocks() {
var value = "";
var name = "";
var substring = "-";
$.getJSON("https://finance.google.com/finance/info?client=ig&q=TSLA,HM-B,AAPL&callback=?", function(json) {
json.forEach(function(v) {
//if(v.cp.includes(substring)){
//}
//
//else{
//}
name += v.t + "<br>";
value += v.cp + " %" + "<br>";
document.getElementById('name').innerHTML = name;
document.getElementById('value').innerHTML = value;
});
setTimeout(stocks, 10000);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
<div id="name" style="float:left ; padding-right:10px"></div>
<div id="value" style="text-align:right; width:140px"></div>
</div>
myElement.style.color = '#ccc'?.innerHTML = ...parts out of the.forEach()"loop". No need to change the DOM for each element if only the value ofname/valueafter the last element is relevant.