Skip to content

Instantly share code, notes, and snippets.

@travismillerweb
Created February 18, 2014 21:41
Show Gist options
  • Save travismillerweb/9080827 to your computer and use it in GitHub Desktop.
Save travismillerweb/9080827 to your computer and use it in GitHub Desktop.
JS - Add and Remove Rules Directly to Stylesheets
/*
JS - Add and Remove Rules Directly to Stylesheets
Reference Site: http://davidwalsh.name/ways-css-javascript-interact
*/
function addCSSRule(sheet, selector, rules, index) {
if(sheet.insertRule) {
sheet.insertRule(selector + "{" + rules + "}", index);
}
else {
sheet.addRule(selector, rules, index);
}
}
// Use it!
addCSSRule(document.styleSheets[0], "header", "float: left");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment