On 21/09/06, Justin Carter <[EMAIL PROTECTED]> wrote:
> 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.
You would probably check that before calling the function, or after
'var matches' add the following:
if(matches.length != 3) return value;
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/