I have an HTML table with a lot of numbers.
Is it possible to have a table cell change background color if the value inside that cell (or column) equals or is less than
Here is the example //CSS
.lowerthan100{
background-color:red;
color:white;
}
.higherthan100{
background-color:white;
color:red;
}
//JAVASCRIPT
$('#mytable td').each(function() {
if(parseInt($(this).html())>100){
$(this).addClass("higherthan100");
}else if (parseInt($(this).html())<100){
$(this).addClass("lowerthan100");
}
});
//HTML
99 101
200 50
You can populate more class in CSS and else if statements, if you need more conditions.
Here is the live example http://jsfiddle.net/kayadiker/DL6U2/2/