Get DOM element by ID selector - Javascript DOM

Javascript examples for DOM:Document querySelector

Description

Get DOM element by ID selector

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 om*/
(function () {
    var date = new Date().toISOString().substring(0, 10),
        field = document.querySelector('#date');
    field.value = date;
    console.log(field.value);
})();
    });

      </script> 
   </head> 
   <body> 
      <input id="date" type="date" value="2019-11-11">  
   </body>
</html>

Related Tutorials