Skip to content

Instantly share code, notes, and snippets.

@amitasaurus
Created August 20, 2018 12:44
Show Gist options
  • Save amitasaurus/dd896848dcd065e9d592259e5d4b860a to your computer and use it in GitHub Desktop.
Save amitasaurus/dd896848dcd065e9d592259e5d4b860a to your computer and use it in GitHub Desktop.
Adding Styles through JS
let css = `h1{ font-size : 14px;}`;
let head = document.head || document.getElementsByTagName('head')[0];
let style = document.createElement('style');
style.type = 'text/css';
if (style.styleSheet) {
// This is required for IE8 and below.
style.styleSheet.cssText = css;
} else {
style.appendChild(document.createTextNode(css));
}
head.appendChild(style);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment