Skip to content

Instantly share code, notes, and snippets.

@jamenlyndon
Last active August 29, 2015 14:26
Show Gist options
  • Save jamenlyndon/6fc833a59c981bff7678 to your computer and use it in GitHub Desktop.
Save jamenlyndon/6fc833a59c981bff7678 to your computer and use it in GitHub Desktop.
Modify global CSS with JS
function css(selector, property, value) {
for (var i=0; i<document.styleSheets.length;i++) {
try { document.styleSheets[i].insertRule(selector+ ' {'+property+':'+value+'}', document.styleSheets[i].cssRules.length);
} catch(err) {try { document.styleSheets[i].addRule(selector, property+':'+value);} catch(err) {}}//IE
}
}
// Example usage:
css('.header', 'border', '5px solid green');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment