[thelist] Variable Stylesheets?

Aleem aleem at mindless.com
Mon Dec 3 03:11:39 CST 2001


LK,
	Here is what I believe would be a client side solution, using
the StyleSheet object:

alert(document.styleSheets[0].cssText);
Would return the entire style sheet

document.styleSheets[0].cssRules[0].style = "color; red"
Would change the text color (Dynamic stylesheets!)

alert(document.styleSheets[0].cssRules[0].style.cssText);
would return the text inside the first style element in the first
stylesheet 
cssRules is supported by IE 5
(http://www.irt.org/xref/StyleSheet.htm#cssRules[])
it does not work on NNav, however.

A work around to this is using the StyleSheet Properties disabled tag
attribute which allows you to disable/enable one or more specific
StyleSheets (Your server-side solution proves to be much better,
ofcourse). 
This tag works on IE4, NN6
(http://www.irt.org/xref/StyleSheet.htm#disabled)

More details on the Style Reference are available at mozzila:
http://www.mozilla.org/docs/dom/domref/dom_style_ref.html#998118

In due time this object will be fully supported by the new generation of
browsers and the stylesheet will be open to all kinds of client-side
javascripting and dynamic properties - even the server-side scripting
will benefit from it.

Your solution, however, bypasses all the limitations, but the idea had
been realized some time back, even IE4 (supposedly) implemented support
for the cssRules object.

You can view a working example at the bottom of this page:
http://developer.apple.com/internet/javascript/styles.html#example
(note this is not the traditional JS changing
document.object.style.attribute = value; rather, it directly references
the styleSheet/style object)

- Aleem


-----Original Message-----
From: thelist-admin at lists.evolt.org
[mailto:thelist-admin at lists.evolt.org] On Behalf Of lon.kraemer
Sent: December 3, 2001 2:44 AM
To: thelist at lists.evolt.org
Subject: Re: [thelist] Variable Stylesheets?

Hi Aleem,


> I may be wrong, but isn't this concept applicable using javascript and
> DOM style/styleSheet objects, which also save a trip back to the
server
> since they are client side ? If the .js file and .css files are both
> external, then it amounts to pretty much the same as what you have
> suggested save a trip back to the server.
>
> Once again, I've joined the discussion late, so correct me if I'm
wrong.

No, not wrong, but the technique in discussion is most definitely
server-side. I certainly would be interested in any similar technique
you've
developed using client-side scripting.

> Thanks,
> Aleem

LK





More information about the thelist mailing list