HTML DOM className Property

Definition and Usage

The className property sets or returns the class attribute of the element.

Syntax

object.className=classname

Example

This example demonstrates two methods of obtaining the class attribute of the <body> element:

<html>
<body id="myid" class="mystyle">
<script type="text/javascript">
x=document.getElementsByTagName('body')[0];
document.write("Body CSS class: " + x.className);
document.write("<br />");
document.write("An alternate way: ");
document.write(document.getElementById('myid').className);
</script>
</body>
</html>

Output:

Body CSS class: mystyle
An alternate way: mystyle