Get text content from node via textContent attribute - Javascript DOM

Javascript examples for DOM:Element textContent

Description

Get text content from node via textContent attribute

Demo Code

ResultView the demo in separate window

<html lang="en">
   <head> 
      <title>Document</title> 
      <script>
      function jsTest()/* w  w  w .  j a va  2s .c o  m*/
      {
         var x = document.getElementById("fruits");
         var y = x.children[2].textContent;
         console.log(y);
      }
   
      </script> 
   </head> 
   <body> 
      <ul id="fruits"> 
         <li>Apple</li> 
         <li>Banana</li> 
         <li>Pear</li> 
         <li>Orange</li> 
      </ul> 
      <button onclick="jsTest()">TRY</button>  
   </body>
</html>

Related Tutorials