I am trying to get the background color of an element:
var bgcolor = $('.myclass').first().css('background-color')
and trying to convert this to hex
function rgbhex(color) {
return "#" + $.map(color.match(/\b(\d+)\b/g), function (digit) {
return ('0' + parseInt(digit).toString(16)).slice(-2);
}).join('');
}
but the problem is, I am getting in FireFox "transparent"
for bgcolor
, where rgbhex()
is failing with error:
TypeError: elems is null
but in chrome, I am getting rgba(0, 0, 0, 0)
and rgbhex()
is working for this.
how can I get the css color in crossbrowser format and convert it to hex?