Skip to content

Instantly share code, notes, and snippets.

@ryantownsend
Last active December 15, 2015 16:19
Show Gist options
  • Select an option

  • Save ryantownsend/5288539 to your computer and use it in GitHub Desktop.

Select an option

Save ryantownsend/5288539 to your computer and use it in GitHub Desktop.
Append CSS as a stylesheet using JS.
// source: http://alexsexton.com/blog/2013/03/deploying-javascript-applications/
var css = '#generated{css:goes-here;}';
var head = document.head || document.getElementsByTagName('head')[0],
var style = document.createElement('style');
style.type = 'text/css';
if (style.styleSheet) {
style.styleSheet.cssText = css;
}
else {
style.appendChild(document.createTextNode(css));
}
head.appendChild(style);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment