Get text value from <span> - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Span

Description

Get text value from <span>

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 v a2 s . com
var x = document.getElementById('pids').innerText;
var y = JSON.parse(x);
console.log(y.length);
    }

      </script> 
   </head> 
   <body> 
      <span id="pids" style="display:none">["26551826","22956811","22959266"]</span>  
   </body>
</html>

Related Tutorials