I am trying to do something that, in my opinion, was very simple, but not very successful. I have two long lists of ratings for comparison, each pair sitting in its own div. I am in search of a function that I could specify div ids, and have a different reflection in the third div. If the indicator is positive, apply one class, and if negative, apply another.
<style> .positive { color: green; } .negative { color: red; } </style> <div id = "score">50</div> <div id = "benchmark">30</div> <div id = "diff"></div>
and in my javascript:
$(window).ready(function() { $('#diff').html(diff); }); var diff = calc("score", "benchmark"); function calc(divID1, divID2) { div1 = document.getElementById(divID1); metric = div1.innerHTML; div2 = document.getElementById(divID2); benchmark = div2.innerHTML; c = Math.abs(a) - Math.abs(b);
I have loaded D3 and jQuery. The numbers in the divs columns are dynamically generated through other functions, so I cannot hard code the style.
source share