[Javascript] Changing the CSS class of an element

Matt Barton javascript at mattbarton.org
Tue May 18 09:23:28 CDT 2004


Hi Terry,

Very easy this.  Use the className property of the element in question.

    document.getElementById('mytablecell').className = 'green';

HTH

Matt

----- Original Message ----- 
From: Terry Riegel
To: JavaScript
Sent: Tuesday, May 18, 2004 3:23 PM
Subject: [Javascript] Changing the CSS class of an element


Is there a way to change the class of an element

For example:

I would like to change
<td class="blue" id="mytablecell">
to
<td class="green" id="mytablecell">

currently I am doing something like this.

document.getElementById('mytablecell').style.backgroundColor = '#ffffff';

I would prefer to change the whole style if I can then I can change a lot of
things at once.


Terry Riegel
-----------------
MAILKEY: 2524427349







_______________________________________________
Javascript mailing list
Javascript at LaTech.edu
https://lists.LaTech.edu/mailman/listinfo/javascript




More information about the Javascript mailing list