Last active
December 14, 2015 06:58
-
-
Save bitboxx/5046552 to your computer and use it in GitHub Desktop.
Javascript: dynamically adding CSS in to document
This file contains hidden or 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
function loadCSS(css) { | |
var styleElement = document.createElement("style"); | |
styleElement.type = "text/css"; | |
if (styleElement.styleSheet) { | |
styleElement.styleSheet.cssText = css; | |
} else { | |
styleElement.appendChild(document.createTextNode(css)); | |
} | |
document.getElementsByTagName("head")[0].appendChild(styleElement); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment