Skip to content

Instantly share code, notes, and snippets.

@watert
Created July 19, 2013 09:16
Show Gist options
  • Save watert/6037843 to your computer and use it in GitHub Desktop.
Save watert/6037843 to your computer and use it in GitHub Desktop.
dynamicly add css contents for IE6+ and modern browsers. source: http://stackoverflow.com/questions/3922139/add-css-to-head-with-javascript
/**
* dynamicly add css contents for IE6+ and modern browsers.
* source: http://stackoverflow.com/questions/3922139/add-css-to-head-with-javascript
* example: addcss("strong { color: red }");
*/
function addcss(css){
var head = document.getElementsByTagName('head')[0];
var s = document.createElement('style');
s.setAttribute('type', 'text/css');
if (s.styleSheet) { // IE
s.styleSheet.cssText = css;
} else { // the world
s.appendChild(document.createTextNode(css));
}
head.appendChild(s);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment