You might need to modify the way i get the variable cellAbove
, but take a look at this: (http://jsfiddle.net/D5TQy/3/)
var cell = $('tr').last().find('td');
var cellAbove = $('tr').first().find('td');
var threshold= 100; //defines what is `too much` difference
cell.each(function() {
var column = $(this).index();
var cell_value = $(this).text();
var valueAbove = cellAbove.eq(column).text();
//red
if (cell_value - valueAbove > threshold) {
$(this).addClass('veryOutsideFromTarget');
}
//yellow
else if ((cell_value - valueAbove > 0)) {
$(this).addClass('outsideTarget');
}
//green
else{
$(this).addClass('insideTarget');
}
});
Notes:
Make use of classes instead of modifying the background inline style. This way is even more simple to read and understand the code.
I modified the logic of your conditions and this way makes more sense.