Created
May 2, 2012 06:21
-
-
Save hideki-a/2574404 to your computer and use it in GitHub Desktop.
Dynamic style element
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
// See Also: http://www.phpied.com/dynamic-script-and-style-elements-in-ie/ | |
// http://code.skyward-design.net/js/code_19.html | |
var head = document.getElementsByTagName("head")[0], | |
style = document.createElement("style"), | |
def = "body { color: red; }"; | |
head.appendChild(style); | |
if (typeof window.attachEvent === "object" && style.styleSheet) { | |
// Less than IE9 | |
style.styleSheet.cssText = def; | |
} else { | |
style.appendChild(document.createTextNode(def)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment