Return to Snippet

Revision: 30760
at August 21, 2010 01:58 by math89


Initial Code
function Rgb() {
     var red = returnHex(200);
     var green = returnHex(255);
     var blue = returnHex(155);
     var hex = "#" + red + green + blue;
                        
     alert(hex);            
}
  
// Convert to Hex
function returnHex(num) {
     // Hex can store 16 different values in 1 character
     if (num == null) return "00";
     num = num.length < 2 ? "0" + num : num
     return num.toString(16);
}

Initial URL
http://www.devcurry.com/2010/08/convert-rgb-to-hexadecimal-using.html

Initial Description
You have a RGB value and want to convert it into Hexadecimal mode, here’s how to do it using JavaScript.

Initial Title
Convert RGB to Hexadecimal using JavaScript

Initial Tags
color

Initial Language
JavaScript