Use document.querySelector to get elements - Javascript DOM

Javascript examples for DOM:Document querySelector

Description

Use document.querySelector to get elements

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 .  ja v a2 s.c o  m*/
var input = document.querySelector('input');
var p = document.querySelector('p');
var i = 0;
input.addEventListener('keyup', function() {
   p.innerHTML = input.value.length;
})
    }

      </script> 
   </head> 
   <body> 
      <input> 
      <p>The length of the value</p>  
   </body>
</html>

Related Tutorials