Created
July 19, 2013 09:16
-
-
Save watert/6037843 to your computer and use it in GitHub Desktop.
dynamicly add css contents for IE6+ and modern browsers.
source: http://stackoverflow.com/questions/3922139/add-css-to-head-with-javascript
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
/** | |
* dynamicly add css contents for IE6+ and modern browsers. | |
* source: http://stackoverflow.com/questions/3922139/add-css-to-head-with-javascript | |
* example: addcss("strong { color: red }"); | |
*/ | |
function addcss(css){ | |
var head = document.getElementsByTagName('head')[0]; | |
var s = document.createElement('style'); | |
s.setAttribute('type', 'text/css'); | |
if (s.styleSheet) { // IE | |
s.styleSheet.cssText = css; | |
} else { // the world | |
s.appendChild(document.createTextNode(css)); | |
} | |
head.appendChild(s); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment