var css = 'body {color:red}'; var style = document.createElement('style'); style.setAttribute("type", "text/css"); var head = document.getElementsByTagName('head')[0]; head.appendChild(style); if (style.styleSheet) { // IE style.styleSheet.cssText = css; } else { // modern browser var node = document.createTextNode(css); style.appendChild(node); }
1/05/2016
Loading CSS Styleheet in IE8, E7, and IE6 Dynamically
Since innerHTML doesn't work in IE8 and below.
Here is a hack for inserting CSS Styleheet in IE8 using javascript programmatically.