getElementsByClassName to get element by class value - Javascript DOM

Javascript examples for DOM:Document getElementsByClassName

Description

getElementsByClassName to get element by class value

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){//from  w  w w  . j a va2s. c  om
var results = document.getElementsByClassName("myClass");
for (var i = 0; i < results.length; i++) {
    results[i].style.display = 'none';
}
    }

      </script> 
   </head> 
   <body> 
      <div class="myClass">
         Test
      </div> 
      <div class="myClass">
         Test
      </div>  
   </body>
</html>

Related Tutorials