javascript - Changed background color based on td number using ID -
i having trouble changing background color of table cell based on value. have made work using
var elems = document.getelementsbytagname(td);
but make check number id tag. reason because have multiple rows variable range of , bad (green or red) different.
my javascript looks like:
var elems = document.getelementbyid("cho"); (var i=0, m=elems.length; i<m; i++) { if (elems[i].innerhtml>7) { elems[i].style.background="#ef0401";} if (elems[i].innerhtml<=7) { elems[i].style.background="#4cb900";} }
i tried looking up, have replace innerhtml children?
here html
<table class="medical"> <tr> <td class="type-txt bg-left"><span class="type-name">total cholesterol</span><span class="sm-font">a type of fat</span></td> <td class="bg-right" id="cho">80</td> </tr> <tr> <td class="type-txt bg-left"><span class="type-name">ldl</span><span class="sm-font">"bad" cholesterol</span></td> <td class="bg-right" id="ldl">1</td> </tr> </table>
Comments
Post a Comment