javascript className attribute


  Translation results:

UK [klɑ:s neim] US [klæs nem]

Category name

javascript className attributesyntax

Function: Set or return the class attribute of the element.

Syntax: bodyObject.className=classname

javascript className attributeexample

<html>
<head>
    <meta charset="UTF-8">

</head>
<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>

Run instance »

Click the "Run instance" button to view the online instance

Home

Videos

Q&A