Solved

Google Chrome CSS Change Class Property

Posted on 2011-02-27
3
427 Views
Last Modified: 2013-11-10
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
Comment
Question by:mikehirsch
  • 2
3 Comments
 
LVL 40

Accepted Solution

by:
gurvinder372 earned 500 total points
ID: 34994897
i guess your problem is similar to
http://stackoverflow.com/questions/2961544/cssrules-is-empty

please check
0
 

Author Comment

by:mikehirsch
ID: 34994927
Thanks but I did try that and was unable to get it to work after about an hour playing around with it.. ARGH.
0
 

Author Comment

by:mikehirsch
ID: 35003642
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

So you have coded your own WordPress plugin and now you want to allow users to upload images to a folder in the plugin folder rather than the default media location? Follow along and this article will show you how to do just that!
#Citrix #Internet Explorer #Enterprise Mode #IE 11 #IE 8
In this tutorial viewers will learn how to style different bullet points for unordered lists in CSS. Begin with a normal unordered list; the default bullet point is a solid circle: In the CSS, create a defined class of unordered list by typing "ul.S…
In this tutorial viewers will learn how to style rounded corners for elements in CSS using the border-radius property Begin with a normal styled element such as a div: To style all four corners of the div to be the same degree of roundness, use the …

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now