Use both document.getElementById and Element.getElementsByTagName - Javascript DOM

Javascript examples for DOM:Document getElementsByTagName

Description

Use both document.getElementById and Element.getElementsByTagName

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
   </head> 
   <body> 
      <div id="title"> 
         <h1>Javascript Lesson 1</h1> 
         <p>The basics</p> 
      </div> 
      <script type="text/javascript">
var titleElement = document.getElementById("title");
var titleChildren = titleElement.getElementsByTagName("H1");
console.log(titleChildren);
console.log(titleChildren[0].innerHTML);

      </script>  
   </body>/*w  w w  .  j  a va 2 s.c o m*/
</html>

Related Tutorials