Is there a quick way I can covert any css color such as #ffe
, whitesmoke
, or hsl(20,50%,80%)
, to a rgb color like rgb(140,75,20)
?
Can I use the .css()
method on a variable to convert the color to rgb somehow?
Is there a quick way I can covert any css color such as #ffe
, whitesmoke
, or hsl(20,50%,80%)
, to a rgb color like rgb(140,75,20)
?
Can I use the .css()
method on a variable to convert the color to rgb somehow?
This may answer your question - RGB to Hex and Hex to RGB
function hexToRgb(hex) {
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
return result ? {
r: parseInt(result[1], 16),
g: parseInt(result[2], 16),
b: parseInt(result[3], 16)
} : null;
}
alert( hexToRgb("#0033ff").g ); // "51";