-
-
Save larsberg/f96599fb973c54b34881 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
if (!document.styleSheets.length) document.head.appendChild(document.createElement('style')); | |
var sheet = document.styleSheets[document.styleSheets.length - 1]; | |
var rules = {}; | |
function cssRule(selector, styles) { | |
var index; | |
if (selector in rules) { | |
index = rules[selector]; | |
sheet.deleteRule(index); | |
} else { | |
index = rules[selector] = sheet.cssRules.length; | |
} | |
sheet.insertRule(selector + " {" + styles + "}", index); | |
// Don't support for <IE9 sheet.addRule, sorry, ha! | |
} |
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
cssRule('body', 'background-color: black;') | |
cssRule('body', 'background-color: white;') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment