Get an array of element from html using getElementsByTagName() method - Javascript Array Operation

Javascript examples for Array Operation:Array Element

Description

Get an array of element from html using getElementsByTagName() method

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <script>
        var myList = document.getElementsByTagName('h1');
        console.log(myList.length)
    //from  w w w  .  j  av  a2s .c om
      </script> 
   </head> 
   <body> 
      <div class="item"> 
         <h1 id="Python">Python</h1> 
      </div> 
      <div class="item"> 
         <h1 id="C++">C++</h1> 
      </div> 
      <div class="item"> 
         <h1 id="PHP">PHP</h1> 
      </div>   
   </body>
</html>

Related Tutorials