473,394 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Apply style changes to a whole CSS class

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?
Sep 19 '05 #1
3 16488
ASM
Waffeloo wrote:
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>
<input type=checkbox onclick="javascript:changeclass('div_1','spec_9')" >
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[i].className=='truc') D[i].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[i].style.textDecoration=='none') D[i].style.textDecoration='underline';
--
Stephane Moriaux et son [moins] vieux Mac
Sep 19 '05 #2
Waffeloo wrote:
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/comp.lang.javascript/browse_frm/thread/3daffc9ed1c3afee/f800fd5529ed50b0?q=change+CSS+style+rule&rnum=6&hl =en#f800fd5529ed50b0>


--
Rob
Sep 19 '05 #3
Waffeloo wrote:
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.
Sep 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Louis. | last post by:
Hi all, One can connect a CSS style to a HTML tag. I want to create a text in the style footer. I can do: <font class="footer">Here is my great footer.</font> However, the <font> tag is...
7
by: Troy Heber | last post by:
Can anyone tell me how to force an immediate apply of system based registry changes. I have an application written in C# that updates the registry. However I’m forced to logout and log back in for...
144
by: Natt Serrasalmus | last post by:
After years of operating without any coding standards whatsoever, the company that I recently started working for has decided that it might be a good idea to have some. I'm involved in this...
1
by: Hardy Wang | last post by:
Hi all, I have a drop down list with some items, and one of the item contains very long text. I want to limit the width of the drop down itself, but when I click down arrow to pull down the...
4
by: Mr Newbie | last post by:
//This is really fundemental, but I dont seem to be able to understand why my table text wont render as I want it. I have a style sheet which has many styles for all the standard tags etc. The body...
38
by: looping | last post by:
For Python developers around. >From Python 2.5 doc: The list of base classes in a class definition can now be empty. As an example, this is now legal: class C(): pass nice but why this...
3
by: spolsky | last post by:
hi, it is possible to apply multiple styles as shown in the following example. <STYLE TYPE="text/css"><!-- BODY { background-color:salmon; } P { margin-left:20px; } .clsCode {...
4
by: planb | last post by:
Hi, I'd like to have a rollover like effect when a input field has the focus, any idea of how to do this with just CSS (easy enough with javascript)? What I'm thinking of is having a tips box...
9
by: =?Utf-8?B?QnJpYW4gQ29vaw==?= | last post by:
I want to open a text file and format it into a specific line and then apply color to a specific location of the text and then display it in a RichTextBox after all of this is done. I can do all...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.