title: On button click focus input in JavaScript
body: <p>I am trying to <code>autofocus</code> input on button click but it doesn't work. Code can be found here for edit: <a href="https://www.w3schools.com/code/tryit.asp?filename=FPPCFP5RTU9E" rel="noreferrer">https://www.w3schools.com/code/tryit.asp?filename=FPPCFP5RTU9E</a></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;input type="text" id="myText" autofocus&gt;
  
  &lt;button onclick="myFunction()"&gt;Focus Input&lt;/button&gt;
  
  &lt;p id="demo"&gt;&lt;/p&gt;
  
  &lt;script&gt;
    function myFunction() {
        document.getElementById("myText").autofocus = true;  
    }
  &lt;/script&gt;</code></pre>
  </div>
  </div>
  </p>