Created
September 28, 2011 16:52
-
-
Save barneycarroll/1248467 to your computer and use it in GitHub Desktop.
Cross-browser method for injecting passed CSS into the document
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
function writeStyle(rules){ | |
var head = document.getElementsByTagName('head')[0], | |
el = this.el || document.createElement('style'), | |
rules = rules || ''; | |
if(!this.el) | |
el.type = 'text/css'; | |
if(el.styleSheet){ | |
el.styleSheet.cssText = rules; | |
} | |
else{ | |
$(el).empty() | |
el.appendChild(document.createTextNode(rules)) | |
}; | |
if(!this.el) | |
head.appendChild(el); | |
this.el = el; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment