[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 443
  • 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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