Suppose a HTML element's
id is known, so the element can be refereced using:
var element = document.getElementById(element_id); element.className += " " + newClassName;
Voilà. This will work on pretty much every browser ever. The leading space is important, because the
className property treats the css classes like a single string, which ought to match the
class attribute on HTML elements (where multiple classes must be separated by spaces).
In prototype, for instance:
// Prototype automatically checks that the element doesn't already have the class $(element_id).addClassName(newClassName);
See how much nicer that is?!