On 21/09/06, Christof Donat <[EMAIL PROTECTED]> wrote:
> Hi,
>
> > I'm using this function (getCV) to do the trick: [...]
>
> Why are you not using toString() to convert the decimal numbers to Hex
> Numbers:
>
> var i = 15;
> alert(i.toString(16)); // alerts 'f'.
>
> Christof
On 21/09/06, Christof Donat <[EMAIL PROTECTED]> wrote:
> Hi,
>
> > I'm using this function (getCV) to do the trick: [...]
>
> Why are you not using toString() to convert the decimal numbers to Hex
> Numbers:
>
> var i = 15;
> alert(i.toString(16)); // alerts 'f'.
>
> Christof
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
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/