Get element class name - Javascript DOM

Javascript examples for DOM:Element className

Description

Get element class name

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <title>Test Page</title> 
      <script type="text/javascript">
            window.onload = function () {
                console.log(document.getElementsByTagName("body")[0].className);
            };//from w w w .  j a v  a 2 s  .c o  m
        
      </script> 
      <style type="text/css">

.testClass { color: green; background-color: red; }


      </style> 
   </head> 
   <body class="testClass"> 
      <p>Test Content</p>  
   </body>
</html>

Related Tutorials