Access the content of an HTML element from a node list - Javascript DOM

Javascript examples for DOM:Document getElementsByClassName

Description

Access the content of an HTML element from a node list

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  www. j a  v a2s  . co m
var spanarray = document.getElementsByClassName("myclass");
spanarray[0].innerHTML = "ABC"
    }

      </script> 
   </head> 
   <body>  
      <span class="myclass">Text</span> 
      <span class="myclass">Text2</span>   
   </body>
</html>

Related Tutorials