Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS Setting backround color of tablecell dynamically? Re: Setting backround color of tablecell dynamically?

#93613
Mottie
Member

Hi XStone!

Sure it’s possible. I put together a demo which basically makes the cell color red if less than 1/3 of the max, yellow if less than 1/2 of max and green otherwise (demo):

$('table td').each(function(){
var c = 'high',
t = $(this),
val = parseInt( t.text(), 10 );

if (val <= max/3 ) { c = 'low'; }
if (val > max/3 && val <= max/2) { c = 'medium'; }
t.addClass(c);
});

This is assuming you’re using integers, if not, change the parseInt( t.text(), 10); to parseFloat( t.text() );