?
Solved

Google Chrome CSS Change Class Property

Posted on 2011-02-27
3
Medium Priority
?
437 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 40

Accepted Solution

by:
Gurvinder Pal Singh earned 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article offers some helpful and general tips for safe browsing and online shopping. It offers simple and manageable procedures that help to ensure the safety of one's personal information and the security of any devices.
This article discusses four methods for overlaying images in a container on a web page
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…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses
Course of the Month11 days, 10 hours left to enroll

752 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