Assign Or Get Class Name Attribute With JavaScript
To get the class of an element with JavaScript you use the className property of the element object. Take the following section of HTML code.
<div id="adiv" class="theClass">some text</div>
Use the following bit of code to print off the class name of the div element in a message box.
alert(document.getElementById('adiv').className);
To set the class name to something else you can use the same property, but in this case just pass it a value. The following example changes the class name of the div element to 'newClass'.