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!
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!
You have to separate all three components from the Hex definition, then convert them to decimal. This works:
Try this:
http://jsfiddle.net/AlienWebguy/AfVhs/1/
You could use:
What about this algorithm?
http://www.javascripter.net/faq/hextorgb.htm
You could even create a JQuery plugin that uses that algorithm. I think it would be cool. I don't know if there exists one already.
.css("background-color")
will return rgb http://api.jquery.com/css/here is the fiddle http://jsfiddle.net/3nigma/msRqv/1/
Purely working with the string you have, you could something like this :
First, extract the two hexadecimal digits for each color :
Then, convert them to decimal :
And, finally, get your
rgb()
string as a result :And you get as output :