On 9/21/06, Sam Collett <[EMAIL PROTECTED]> wrote:
> Expanding on that, this is a basic function to convert to hex. No
> fancy regexp's or string parsing needed:
>
> function RGBToHex(value)
> {
>         var re = /\d+/g;
>         var matches = value.match(re);
>         var r = parseInt(matches[0]);
>         var g = parseInt(matches[1]);
>         var b = parseInt(matches[2]);
>         return "#" + r.toString(16) + g.toString(16) + b.toString(16);
> }
>
> It will work with "rgb(255,255,255)", "rgb ( 255,  255,  255 )" etc

That probably takes care of most of it :) Just a check to see whether
the original string starts with a # and it'd be pretty close to a
working solution.

I wonder if anyone can confirm what values Safari and other browsers
return as the computed style value for color? Hopefully our bases
would be covered with just the hex value prefixed with # and the RGB
notation. Does RGBA ever come into it, or does the alpha value get
pushed into the opacity property or something?

_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to