Skip to content

Instantly share code, notes, and snippets.

@llagerlof
Created August 28, 2018 12:11
Show Gist options
  • Save llagerlof/441623e2959b858c65597b5b05ae2f59 to your computer and use it in GitHub Desktop.
Save llagerlof/441623e2959b858c65597b5b05ae2f59 to your computer and use it in GitHub Desktop.
How to change CSS rules dinamically
/*
source: https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet/insertRule
*/
var styleElement = document.createElement('style');
document.head.appendChild(styleElement);
styleSheet = styleElement.sheet;
styleSheet.insertRule("p, h1, h2, h3 {font-family: Courier New; color: blue;", 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment