Last active
August 3, 2016 19:42
-
-
Save ArtOfCode-/392ce80b67c762d3c478b85136a86bc3 to your computer and use it in GitHub Desktop.
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
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