Skip to content

Instantly share code, notes, and snippets.

@alanedwardes
Created December 15, 2011 22:03
Show Gist options
  • Save alanedwardes/1483114 to your computer and use it in GitHub Desktop.
Save alanedwardes/1483114 to your computer and use it in GitHub Desktop.
JavaScript function to convert a hexadecimal colour representation to an RGB object, {r: n, g: n, b: n}
function hexToRGB(hex){
hex = hex.replace('#', '');
return {
'r': parseInt(hex.substring(0, 2), 16),
'g': parseInt(hex.substring(2, 4), 16),
'b': parseInt(hex.substring(4, 6), 16)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment