Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Cross-browser method for injecting passed CSS into the document
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
You can’t perform that action at this time.