Google Chrome CSS Change Class Property

The included function works perfect in Firefox, IE, and Safari but returns Cannot Read Property Length for rules.length.
I have spent a couple hours on this one and before going crazy I thought I would pose my question here hoping someone might have a solution . I have tried several but none work so far.
Thanks In Advance
// set the value of a property of a CSS Rule
function changeClassProperty(sClassName,sProperty,sValue) {
  sClassName="."+sClassName;
  var sheets = document.styleSheets;
  var rules;
  var styleObj;
  for (i=0;i< sheets.length; i++) {
    rules=sheets[i].cssRules;
        if (!rules)
    {rules=sheets[i].rules;}
    for (var j=0; j<rules.length; j++) {
      if (rules[j].selectorText && rules[j].selectorText==sClassName) {

        styleObj=rules[j].style;
        styleObj[sProperty]=sValue;
        break;
      }
    }
  }
}

Open in new window

error.png
mikehirschAsked:
Who is Participating?
 
Gurvinder Pal SinghCommented:
i guess your problem is similar to
http://stackoverflow.com/questions/2961544/cssrules-is-empty

please check
0
 
mikehirschAuthor Commented:
Thanks but I did try that and was unable to get it to work after about an hour playing around with it.. ARGH.
0
 
mikehirschAuthor Commented:
Seems to be working now. Not sure if there were caching issues at my home computer but loaded it up in chrome at my shop and all is good. So the Stackoverflow solution seemed to do the trick..
Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.