[Javascript] Changing the CSS class of an element

Mike Dougherty mdougherty at pbp.com
Tue May 18 09:44:23 CDT 2004


Please follow this very useful suggestion with the regexp replace example to manage multiple 
classnames, it's (IMO) the clever-est part of this solution.

On Tue, 18 May 2004 16:37:17 +0000
  Hakan Magnusson <hakan at backbase.com> wrote:
>It's the way of doing it. Also remember the previous discussion on the list regarding multiple 
>classes on one element. This is perfectly valid:
>
>document.getElementById('mytablecell').className = "myClass yourClass";
>
>mytablecell will then get the style definitions in both classes, and if you have overlapping 
>properties, the ones in yourClass will be used (since it is the last one defined in your class 
>attribute)
>
>Useful if you want to have a "disabled" class, for example, that only changes the background- and 
>forground colors to a "disabled look".



More information about the Javascript mailing list