[thelist] changing class style with JS

Chris Evans chris at fuseware.com
Mon Oct 28 15:00:01 CST 2002

I modified the script from ppk's site to come up with this script:

function changeIt(changeClass,newColor)
     if (!document.styleSheets) return;
     var theRules = new Array();
     if (document.styleSheets[0].cssRules)
	theRules = document.styleSheets[0].cssRules
     else if (document.styleSheets[0].rules)
	theRules = document.styleSheets[0].rules
     else return;
     for (i=0;i<theRules.length;i++)
         if (theRules[i].selectorText != null &&
theRules[i].selectorText.indexOf(changeClass) > -1)
	    theRules[i].style.color = newColor;

It seems to work in most modern browsers, and when it doesn't work, it
doesn't throw any errors.  Since the fucntionality is a "nice, but not
required", it does the trick.

Thanks for all the suggestions!!
Chris Evans
chris at fuseware.com

More information about the thelist mailing list