[thelist] changing class style with JS
Peter-Paul Koch
gassinaumasis at hotmail.com
Sat Oct 26 09:57:01 CDT 2002
>>Is there a way to change elements of a CSS class using Javascript?
>
>Say you want to change the color of any rule containing class
>"foo" to red --
>
>function changeStyles()
>{
> var ss = document.styleSheets;
> for (i=0;i<ss[0].cssRules.length;i++)
> {
> if ( ss[0].cssRules[i].selectorText.indexOf(".foo") > -1 )
> {
> ss[0].deleteRule(i);
> ss[0].insertRule(".foo { color: rgb(255,0,0); }", i);
> }
> }
>}
>
>Only tested on Moz (1.1)/Win - YMMV :-)
Yes, this is the way to go. For the extreme amounts of browser specific code
that you need, see http://www.xs4all.nl/~ppk/js/index.html?changess.html
ppk
_________________________________________________________________
Get a speedy connection with MSN Broadband. Join now!
http://resourcecenter.msn.com/access/plans/freeactivation.asp
More information about the thelist
mailing list