Created
August 30, 2011 21:21
-
-
Save sx/1182078 to your computer and use it in GitHub Desktop.
add a new stylesheet tag to the head
This file contains 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
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