What would be the easiest way to transform
$('#my_element').css('backgroundColor')
to object like this:
{ r: red_value, g: green_value, b: blue_value, a: alpha_value }
?
var c = $('body').css('background-color');
var rgb = c.replace(/^(rgb|rgba)\(/,'').replace(/\)$/,'').replace(/\s/g,'').split(',');
for(var i in rgb) {
console.log(rgb[i]);
}
Try it here http://jsbin.com/uhawa4
Edit :
var c = $('body').css('background-color');
var rgb = c.replace(/^rgba?\(|\s+|\)$/g,'').split(',');
for(var i in rgb) {
console.log(rgb[i]);
}
or even simpler way, just aiming at numbers
var c = 'rgba(60,4,2,6)';
var rgb = c.match(/\d+/g);
for(var i in rgb) {
console.log(rgb[i]);
}