たぼさんの部屋

いちょぼとのんびり

css.addRuleで物理的cssシートの値を変更・追加

function addCSSRule(selector, css) { 
 var sheets = document.styleSheets, 
  sheet = sheets[sheets.length - 1]; 
 
 if(sheet.insertRule) { 
  sheet.insertRule(selector + '{' +  css + '}', sheet.cssRules.length); 
 }else if(sheet.addRule) { 
  sheet.addRule(selector, css, -1); 
 } 
} 
 
addCSSRule('hoge:after', 'background: red');

変更

function changeRule(theNumber) {
    var theRules = new Array();
    if (document.styleSheets[0].cssRules) {
        theRules = document.styleSheets[0].cssRules;
    } else if (document.styleSheets[0].rules) {
        theRules = document.styleSheets[0].rules;
    }
    theRules[theNumber].style.backgroundColor = '#FF0000';
}