title: getElementsByName returns zero length in Javascript onload handler
body: <p>This question is about HTML with pure JavaScript (no jQuery or further technology).</p>
  <p>I try to write by hand a file with a list of URLs which should appear as links. To reduce typing and avoid inconsistencies, I want to use JavaScript to take a list of <code>li</code> elements and translate it into <code>li</code> elements containing appropriate <code>a</code> elements with the URLs as <code>href</code> and as text.</p>
  <p>Working in this direction, I have arrived at the following code, a bit condensed (no <code>a</code> elements) to show the issue at hand:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;meta http-equiv=&quot;content-type&quot; content=&quot;text/html; charset=UTF-8&quot; /&gt;
  &lt;/head&gt;
  &lt;body onload=&quot;linkify()&quot;&gt;
  &lt;ul&gt;
      &lt;li href=&quot;https://stackoverflow.com/questions/5844732/getelementsbytagname-length-returns-zero&quot; /&gt;
      &lt;li href=&quot;https://stackoverflow.com/questions/26932862/why-does-document-getelementsbyname-have-a-length-of-0-despite-having-elements&quot; /&gt;
      &lt;li href=&quot;https://stackoverflow.com/questions/4057440/is-chrome-s-javascript-console-lazy-about-evaluating-objects&quot; /&gt;
  &lt;/ul&gt;
  &lt;script&gt;
  function linkify () {
      let items = document.getElementsByName( &quot;li&quot; );
      for ( let i = 0; i &lt; items.length; ++i ) {
          item = items.item( i );
          item.innerHTML = item.getAttribute( &quot;href&quot; );
      }
  }
  &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <p>I expect the page to show a list of URLs. However, the list remains three empty list items, no URLs. The debugger tells me that <code>let items = document.getElementsByName( &quot;li&quot; );</code> gets a 0 <code>items.length</code> object so that the <code>for</code>-loop does not do anything.</p>
  <p>I would expect that <code>linkify()</code> is only called when the whole DOM has been loaded, so all three <code>li</code> elements should be found. Where is my error?</p>