I have the JavaScript for converting a HEX value to RGB but I was wondering if I could use jQuery to call the function and insert the HTML?
Here's the JavaScript;
function hex2rgb( colour ) {
var r,g,b;
if ( colour.charAt(0) == ‘#’ ) {
colour = colour.substr(1);
}
r = colour.charAt(0) + ” + colour.charAt(1);
g = colour.charAt(2) + ” + colour.charAt(3);
b = colour.charAt(4) + ” + colour.charAt(5);
r = parseInt( r,16 );
g = parseInt( g,16 );
b = parseInt( b ,16);
return “rgb(” + r + “,” + g + “,” + b + “)”;
}
Update
I'm trying to have it so there is one input field where you type in a hex value, hit enter, and then the RGB value is inserted (maybe in a ghost element or something).