Multiple CSS Classes on an Element
Here’s a little CSS tip that a lot of people are unaware of: you can give an element as many CSS classes as you’d like by adding them to that element’s class attribute separated by spaces.
This is how it looks: <div class="big orange square">. Your div now belongs to three classes: big, orange, and square.
What about adding classes with a script? Just use element.className += ” classname” to add them (that’s space + classname). To subtract? Set element.className equal to a string without that element. You can do this by splicing that unwanted class out of a string, using a regular expression to filter it away, or using any other string manipulation. Just set element.className = to your new string. Voila.
technorati tags:css, classes, html, dhtml, javascript