Skip to content

Instantly share code, notes, and snippets.

@sx
Created August 30, 2011 21:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sx/1182078 to your computer and use it in GitHub Desktop.
Save sx/1182078 to your computer and use it in GitHub Desktop.
add a new stylesheet tag to the head
addStyle = function( css ) {
var styleEl = document.createElement( 'style' );
styleEl.rel = 'stylesheet';
// overwrite the stylesheet if it already exist...
if ( styleEl.styleSheet ) { // IE
styleEl.styleSheet.cssText = css;
} else { // !IE
styleEl.appendChild( document.createTextNode( css ) );
}
// attach the stylesheet to the page
document.head.appendChild( styleEl );
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment