Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 440
  • Last Modified:

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
0
mikehirsch
Asked:
mikehirsch
  • 2
1 Solution
 
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now