To change all classes for an element: To replace all existing classes with one or more new classes, set the className attribute: document.getElementById("MyElement").className = "MyClass";