How To append css attributes in ` block can go together with page you insert, inside the ``. – skobaljic Oct 27 '12 at 18:16

0

this is a stupid IE bug, well

try to use @import url("extra.css") all; inside of your css files

bukart
  • 4,906
  • 2
  • 21
  • 40
0

This works in IE 9 and Chrome 22:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
    <head>
        <style id="styleTag" type="text/css">
        </style>
        <script type="text/javascript">
        window.onload = function()
        {
            // append a stylesheet to the page's head (optional)
            var el = document.createElement("link"); 

            el.type = "text/css"; 
            el.rel = "stylesheet"; 

            document.getElementsByTagName("HEAD")[0].appendChild(el);

            // get a reference to the newly added stylesheet
            var css = document.styleSheets[document.styleSheets.length - 1];

            // OR get a reference to an existing stylesheet
            // var css = document.styleSheets[0];

            // add rules to the stylesheet
            css.insertRule("body {background:red;}", css.cssRules.length);
        }
        </script>
    </head>
    <body>
        <h1>Hello, world.</h1>
    </body>
</html>

So you want to focus on referencing the style object, parsing your stylesheets' rules and adding them using insertRule.

hector-j-rivas
  • 771
  • 8
  • 21