Let's say I had Two tables, one has white rows, and one has all green rows.
I currently have stripeTable code that does this for white backgrounds:
function stripeTables($tables) {
$("tbody tr:odd td,tbody tr:odd th", $tables).css("background-color", "#f7f6f6");
}
but I'd want a function that kind of makes the odd rows a bit darker, so that if the base background isn't white, it still just varies 'some RGB' value 'darker' so that I do not have to select a different colour.
Any Ideas on how to do this in a fast way? I was thinking of reading RGB values of the background and then calculating a darker value for it, but i'm quite clueless on how to do that.
UPDATE:
The problem I have with the jquery-color solution is that I need to provide the current bg color, since that can be set on td/th level AND tr level AND TABLE level AND any other element above I can't really be sure that my table will have color X as background. At least not when using $(this).css('background-color'), (this returns undefined if the background-color is not defined at CSS level of thing i'm applying the stripe color to.
using jsColors getRGB function in the way presented over at jQuery and colour calculation
function stripeTables($tables) {
// $("tbody tr:odd td,tbody tr:odd th", $tables).css("background-color", "#f7f6f6");
$("tbody",$tables).each(function () {
$("tr:odd td,tr:odd th", $(this)).css('background-color', function () {
var rgb = getRGB($(this).css('background-color'));
if (!rgb) {
rgb = getRGB("#FFF");
}
for (var i = 0; i < rgb.length; i++) {
rgb[i] = Math.max(0, rgb[i] - 10);
}
var newColor = 'rgb(' + rgb[0] + ',' + rgb[1] + ',' + rgb[2] + ')';
return newColor;
}, 1500);
});
}
code only works with white backgrounds now:
Concrete Updated question, I need to get to know the ACTUAL background color hex/rgb of an element, even if it's not set at that CSS LEVEL