Skip to content

Instantly share code, notes, and snippets.

@andershaig
Created February 26, 2012 13:57
Show Gist options
  • Save andershaig/1916960 to your computer and use it in GitHub Desktop.
Save andershaig/1916960 to your computer and use it in GitHub Desktop.
Hex Color from CSS Output
<div id="color"></div>
<script type="text/javascript">
var css_color = '{% style color my_color %}';
var re = /#?([a-f]|[A-F]|[0-9]){3}(([a-f]|[A-F]|[0-9]){3})?\b/ig;
var hex = re.exec(css_color);
// Print the hex to our div so we can see it working
$('#color').html(hex[0]);
// A more useful example might be setting a
// border color using the appearance settings:
$('#color').css('border', '1px solid ' + hex);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment