title: jQuery to Native JavaScript (simple click call function)
body: <p>I'm trying to convert the following jQuery to native JavaScript, but can't seem to get it to work.</p>
  
  <p><strong>jQuery</strong>:</p>
  
  <pre><code>$(document).ready(function() {
    $("button").click(function() {
      var char = "0123456789abcdefghijklmnopqrstuvwxyz";
      var fullchar = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
      var genHash = "";
      var i;
  
      for (i = 0; i &lt; 8; i++) {
        var rnum = Math.floor(Math.random() * char.length);
        genHash += char.substring(rnum, rnum + 1);
      }
  
      $("input").val(genHash);
    }).click();
  });
  </code></pre>
  
  <p><strong>Native JavaScript</strong>:</p>
  
  <pre><code>function PasswordGenerator() {
      var char = "0123456789abcdefghijklmnopqrstuvwxyz";
    var fullchar = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    var genHash = "";
    var i;
  
    for (i = 0; i &lt; 8; i++) {
      var rnum = Math.floor(Math.random() * char.length);
      genHash += char.substring(rnum, rnum + 1);
    }
  
    document.getElementsByTagName("input").value = genHash;
  }
  
  document.getElementsByTagName("button").onclick = function() {
    PasswordGenerator();
  };
  PasswordGenerator();
  </code></pre>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function PasswordGenerator() {
      var char = "0123456789abcdefghijklmnopqrstuvwxyz";
    var fullchar = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    var genHash = "";
    var i;
  
    for (i = 0; i &lt; 8; i++) {
      var rnum = Math.floor(Math.random() * char.length);
      genHash += char.substring(rnum, rnum + 1);
    }
  
    document.getElementsByTagName("input").value = genHash;
  }
  
  document.getElementsByTagName("button").onclick = function() {
    PasswordGenerator();
  };
  PasswordGenerator();</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;input type="text" /&gt;
  &lt;button&gt;
    Generate Password
  &lt;/button&gt;</code></pre>
  </div>
  </div>
  </p>