Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery # colour to rgba?

Tags:

jquery

colors

rgb

Is it possible to convert a colour as such #ff0000 to rgb?

So convert #ff0000 to rgb(255,0,0);

I'm pretty sure this has got to be possible, I just don't know how. Any insight would be great!

like image 341
daryl Avatar asked Jul 24 '11 08:07

daryl


1 Answers

You could use:

var s = "#ff0000";
var patt = /^#([\da-fA-F]{2})([\da-fA-F]{2})([\da-fA-F]{2})$/;
var matches = patt.exec(s);
var rgb = "rgb("+parseInt(matches[1], 16)+","+parseInt(matches[2], 16)+","+parseInt(matches[3], 16)+");";
alert(rgb);
like image 87
Paul Avatar answered Oct 03 '22 02:10

Paul