I had a very similar need, so I went ahead and wrapped a couple of the logical snippets that I found on the Internet in one jquery extension.
Using can be as simple as $ ('# myTable td'). color () or you can provide an array of colors if you are trying to follow a predefined color scheme.
The following is an example of a gradient between two specified colors based on a <td> text value.
$(document).ready(function(){ var myColors = [ { rng: 0, to: 99, color: { r: 0xff, g: 0x00, b: 0x00 } }, { rng: 100, to: 100, color: { r: 0x00, g: 0xff, b: 0x00 } } ]; $('#myTable td').color({thresh: 110, colors: myColors}); });
JSFiddle: http://jsfiddle.net/danno2000/Yxm4G/
GitHub: https://github.com/danno2000/jquery-color
source share