Created
February 26, 2012 13:57
-
-
Save andershaig/1916960 to your computer and use it in GitHub Desktop.
Hex Color from CSS Output
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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