[Javascript] dynamically reading/changing values in a css class from javascript

Billy Reisinger billy.reisinger at gmail.com
Fri Jun 15 21:23:16 CDT 2007


On Jun 15, 2007, at 4:15 PM, Mike Dougherty wrote:

>
> I still question the appropriateness of messing around with the
> stylesheet definitions via javascript.  If we separate the
> presentation from behavior, then use the behavior layer to manipulate
> the presentation are they really separate or just more convolutedly
> interdependant?

Mike,
I'm not sure if you're being hyperbolic on purpose, but I wanted to  
point out that there are instances when it would be practical to mess  
around with stylesheets; for example, the case in which you are  
writing a debugger and wish to allow the user to declare a new  
stylesheet or edit an existing stylesheet's declarations.   In  
addition, you may want to control some aspect of third-party code  
that you cannot otherwise influence.
In my opinion, the main barrier to messing around with stylesheets  
will be browser support.  You'll find it relatively straightforward  
in Firefox and IE to access stylesheets and their rules from the DOM,  
but for other browsers (like Safari), it's a crap shoot at best.

For the original poster, you should know that in FF, Opera, and IE,  
it is possible and relatively simple to add new style rules via the  
DOM to a stylesheet.  Editing existing rules may be a bit more  
complicated.   I would recommend reading the DOM compatibilty table  
for stylesheets on Quirksmode: http://www.quirksmode.org/dom/ 
w3c_css.html

Good luck!
Billy Reisinger




More information about the Javascript mailing list