Convert RGB Color value to HEX value in Javascript
by satheeshkumar[ Edit ] 2014-02-14 16:48:10
Convert RGB Color value to HEX value in Javascript,
var x = "rgb(255, 255, 255)";
var rtohex = rgb2hex(x);
alert(rtohex);
function rgb2hex(rgb)
{
rgb = rgb.match(/^rgb((d+),s*(d+),s*(d+))$/);
function hex(x) {
return ("0" + parseInt(x).toString(16)).slice(-2);
}
return "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);
}
In the above you will get Hexa color code as "#ffffff".