title: Cannot read property 'innerText' of undefined
body: <p>I am having errors with the following code. I am trying to get the values of id <code>id05</code> if the elements are selected (class selected are the elements selected).</p>
  
  <p>HTML: </p>
  
  <pre><code>&lt;ul id="items" class="clearfix"&gt;
  
    &lt;!-- ---------- this item is selected --------------- --&gt;
    &lt;li class="item folder selected"&gt;
      &lt;a href="/t1/"&gt;
  
        &lt;!-- -------this is the element whose innerTEXT i want ----------- --&gt;
        &lt;span id="id05" class="label" title="t1"&gt;t1&lt;/span&gt;
      &lt;/a&gt;
    &lt;/li&gt;
  
  
    &lt;!-- ---------- this item is also selected --------------- --&gt;
  
    &lt;li class="item folder page selected"&gt;
      &lt;a href="/upl/" target="_blank"&gt;
  
        &lt;!-- -------this is the element whose innerTEXT i want ----------- --&gt;
        &lt;span id="id05" class="label" title="upl"&gt;upl&lt;/span&gt;
      &lt;/a&gt;
    &lt;/li&gt;
  
    &lt;!-- ---------- this item is not selected --------------- --&gt;
  
    &lt;li class="item file"&gt;
      &lt;a href="Ff.html/" target="_blank"&gt;
        &lt;span id="id05" class="label" title="Ff.html"&gt;Ff.html&lt;/span&gt;
      &lt;/a&gt;
    &lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>JS: </p>
  
  <pre><code>function del() {
    var name;
  
    var nam = document.querySelectorAll(".selected");
  
    for (var i = 0; i &lt; nam.length; i++) {
      name = document.getElementById("id05")[i].innerText; //Here is the error
    }
    console.log(name);
  }
  </code></pre>
  
  <blockquote>
    <p>console.log - Uncaught TypeError: Cannot read property 'innerText' of undefined</p>
  </blockquote>