| re: changing class properties
> > there may be a[color=blue][color=green]
> > better way to do it than using JS to dynamicaly change it[/color]
>
> I have form fields that I want to turn on/off (display: none) depending
> on the value of a rolldown.[/color]
This is a bit awkward but it works in IE5:
I can't get it to use named stylesheets. Isn't there a better way to
quit a loop than return 0?
<html>
<head>
<script type="text/javascript">
function setClassStyle(s_s,classname,class_style,style_valu e){
var style_sheet=document.styleSheets[s_s];
for (var j=style_sheet.rules.length-1;j>=0;j--){
var sS=style_sheet.rules[j];
var class_name=sS.selectorText.replace(/\./g,'');
if(class_name==classname){
sS.style[class_style]=style_value;
return 0;
}
}}
</script>
<style type="text/css" name="s">
..a{color: blue}
..b{color: orange}
</style>
</head>
<body>
<a href="javascript:void(0)"
onclick="setClassStyle(0,'a','color','red')">make red</a><br />
<a href="javascript:void(0)"
onclick="setClassStyle(0,'a','color','orange')">ma ke orange</a>
<p class="a">some class a text is here</p>
</body>
</html>
Cheers,
Jeff
[color=blue]
>
> I could give ID's to all them and iterate through a list of them, seems
> awkward.
>
> I can change between the href of a stylesheet, so it can choose an
> external sheet that has the right class properties:
>
> document.styleSheets['a-stylesheet'].href='stylesheet_with_different_class_properties' ;
>
> But it seems to me that I should be able to rewrite the rule in the
> stylesheet, I don't remember how... That would seem to be the most
> maintainable.
>
> Cheers,
> Jeff
>[color=green]
> >
> > Stu
> >
> > "Jeff Thies" <cyberjeff@sprintmail.com> wrote in message
> > news:3F56D5FA.687D3D7F@sprintmail.com...[color=darkred]
> > > I have a number of elements of "some-class".
> > >
> > > I'd like to change the styles of some-class:
> > >
> > > from
> > >
> > > .some-class{color: red; display: block}
> > >
> > > to
> > >
> > > .some-class{color: red; display: none}
> > >
> > > How do I do that?
> > >
> > > Cheers,
> > > Jeff[/color][/color][/color] |