I am currently working on a project wherein values less than or equal to 30% will be colored red in the table. I have written the code below that will check every cell in the table and verify its value and from there execute the condition and highlight it with red if true but somehow it is not doing what I expect. Can you help me understand why it only highlights 0%.
<script>
var td = document.getElementsByTagName("td");
var i = 0, tds = td.length;
for (i; i < tds; i++) {
if (parseFloat(td[i].innerHTML) >= 0.00 && parseFloat(td[i].innerHTML) <= 0.30) {
td[i].setAttribute("style", "background:red;");
}
}
</script>
I have attached a screenshot to give you a better idea of what is happening. From the example below, it should also color 12.50% and 25.00% red.
Your response is greatly appreciated.