Created
August 20, 2018 12:44
-
-
Save amitasaurus/dd896848dcd065e9d592259e5d4b860a to your computer and use it in GitHub Desktop.
Adding Styles through JS
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
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