Apply style changes to a whole CSS class

W

Waffeloo

Hi,
I would like an event to trigger a change the style of all the elements that
belong to some CSS class.

I know it is possible to change the class of an element, for example with:
<script language=javascript>
function changeclass()
{document.getElementById(id).className="class_id";}
</script>
<input type=checkbox onclick="javascript:changeclass()">

But this can only change one element. I would like to change the
"property:list" pairs of a CSS class, so that changes can apply to more
than one element.

Is it possible with javascript?
 
A

ASM

Waffeloo said:
Hi,
I would like an event to trigger a change the style of all the elements that
belong to some CSS class.

I know it is possible to change the class of an element, for example with:
<script language=javascript>
function changeclass()
{document.getElementById(id).className="class_id";}
</script>
<input type=checkbox onclick="javascript:changeclass()">

function changeclass(elem,newClass)
{document.getElementById(elem).className=newClass;}
</script>
But this can only change one element. I would like to change the
"property:list" pairs of a CSS class, so that changes can apply to more
than one element.

Is it possible with javascript?

I think you can't modiy properties of a class defined
(except, perhaps with IE and sheetStyle.rules ?)

You can catch all tags collection of the page
and for each tag with a certain class, change it :

var D = document.getElementsByTagName('*');
for(var i=0;i<D.length;i++)
if(D.className=='truc') D.className="trick";

of course you need 2 classes
of course you need your elements have a class
(it is not always)

you may also search lists elements and change their styles

var L = document.getElementsByTagName('UL')
for(var i=0;i<L.length;i++)
if(L.style.textDecoration=='none') D.style.textDecoration='underline';
 
R

RobG

Waffeloo said:
Hi,
I would like an event to trigger a change the style of all the elements that
belong to some CSS class.

I know it is possible to change the class of an element, for example with:
<script language=javascript>
function changeclass()
{document.getElementById(id).className="class_id";}
</script>
<input type=checkbox onclick="javascript:changeclass()">

But this can only change one element. I would like to change the
"property:list" pairs of a CSS class, so that changes can apply to more
than one element.

Is it possible with javascript?

Yes, this thread should give you all you need:

<URL:http://groups.google.co.uk/group/co...+CSS+style+rule&rnum=6&hl=en#f800fd5529ed50b0>
 
W

Waffeloo

Waffeloo said:
Hi,
I would like an event to trigger a change the style of all the elements
that belong to some CSS class.

I know it is possible to change the class of an element, for example with:
<script language=javascript>
function changeclass()
{document.getElementById(id).className="class_id";}
</script>
<input type=checkbox onclick="javascript:changeclass()">

But this can only change one element. I would like to change the
"property:list" pairs of a CSS class, so that changes can apply to more
than one element.

Is it possible with javascript?

Thanks for the suggestions.
I found an elegant and dirty way: change the name of the class of the <body>
element, and have two sets of CSS rules:

body.class_A .flipflop { nice style }
body.class_B .flipflop { other style }

So I can change the style of many elements with a few lines of code.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top