Skip to content

Instantly share code, notes, and snippets.

@pjeweb
Created March 6, 2013 20:48
Show Gist options
  • Save pjeweb/5102924 to your computer and use it in GitHub Desktop.
Save pjeweb/5102924 to your computer and use it in GitHub Desktop.
Dynamically add css to document
function addCssToDocument(css) {
var styleElement = document.createElement('style');
document.getElementsByTagName('head')[0].appendChild(styleElement);
var isIe = styleElement.styleSheet;
if (isIe)
styleElement.styleSheet.cssText = css;
else
styleElement.appendChild(document.createTextNode(css));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment