inserting cssRules globally with jquery

see: http://stackoverflow.com/questions/4232557/jquery-css-write-into-the-style-tag/4232651#4232651

HTML

<h1>Adding CSS-rules globally</h1>


<div><p>This should be blue </p></div>
<p>and this should be strike-through and red too like the heading </p>


<pre>
$.style.insertRule(['p','h1'],'color:red;');
$.style.insertRule(['p'],'text-decoration:line-through;');
$.style.insertRule(['div p'],'text-decoration:none;color:blue');
</pre>

CSS

h1{font:bold 16px Serif;margin:12px 0;}
pre{background:silver;margin:12px 0;font-size:11px;padding:4px}

JavaScript

(
  function( $ )
  {
    $.style={
              insertRule:function(selector,rules,contxt)
              {
                var context=contxt||document,stylesheet;
                
                if(typeof context.styleSheets=='object')
                {
                  if(context.styleSheets.length)
                  {
                    stylesheet=context.styleSheets[context.styleSheets.length-1];
                  }
                  if(context.styleSheets.length)
                  {
                    if(context.createStyleSheet)
                    {
                      stylesheet=context.createStyleSheet();
                    }
                    else
                    {
                      context.getElementsByTagName('head')[0].appendChild(context.createElement('style'));
                      stylesheet=context.styleSheets[context.styleSheets.length-1];
                    }
                  }
                  if(stylesheet.addRule)
                  {
                    for(var i=0;i<selector.length;++i)
                    {
                      stylesheet.addRule(selector[i],rules);
                    }
                  }
                  else{
                    stylesheet.insertRule(selector.join(',') + '{' + rules + '}', stylesheet.cssRules.length);  
                  }
                }
              }
            }; 
  }
)( jQuery );



$(document).ready(
    function()
    {
        $.style.insertRule(['p','h1'],'color:red;');
        $.style.insertRule(['p'],'text-decoration:line-through;');
            $.style.insertRule(['div p'],'text-decoration:none;color:blue');
     }
);