With this code, I get the RGB color of any TD in my table :
alert($(this).css('background-color'));
the result is :
rgb(0, 255, 0)
Is it possible with jquery to obtain the #000 format or have I to use a function to transform the rgb in #000 format ?
Thanks in advance for your help
Try
var color = '';
$('div').click(function() {
var hexcolor = $(this).css('backgroundColor');
hexc(hexcolor);
alert(color);
});
function hexc(colorval) {
var parts = colorval.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
delete(parts[0]);
for (var i = 1; i <= 3; ++i) {
parts[i] = parseInt(parts[i]).toString(16);
if (parts[i].length == 1) parts[i] = '0' + parts[i];
}
color = '#' + parts.join('');
return color;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With