Skip to content

Instantly share code, notes, and snippets.

@ArtOfCode-
Last active August 3, 2016 19:42
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 ArtOfCode-/392ce80b67c762d3c478b85136a86bc3 to your computer and use it in GitHub Desktop.
Save ArtOfCode-/392ce80b67c762d3c478b85136a86bc3 to your computer and use it in GitHub Desktop.
window.csslib = {
createStyleSheet: function() {
var el = document.createElement("style");
el.appendChild(document.createTextNode(""));
document.head.appendChild(el);
return el.sheet;
},
addRule: function(sheet, selector, rules) {
var ruleString = "";
var keys = Object.keys(rules);
for(var i = 0; i < keys.length; i++) {
ruleString += keys[i] + ": " + rules[keys[i]] + "; ";
}
if(sheet.insertRule) {
sheet.insertRule(selector + "{" + ruleString + "}", 0);
}
else if(sheet.addRule) {
sheet.addRule(selector, ruleString, 0);
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment