title: parentNode.removeChild not removing last element. But why?
body: <p>I am working on a javascript code where I can clone an element, but also want to delete one on click. Cloning works, but I can't remove one.</p>
  
  <p>I have the following elements.</p>
  
  <pre><code>&lt;input list="accountsdeb" name="deblist[1]" id="deblist" autocomplete="off"&gt;
  &lt;input list="accountsdeb" name="deblist[2]" id="deblist" autocomplete="off"&gt;
  </code></pre>
  
  <p>And now I want to remove the last one on click (last = highest number).</p>
  
  <pre><code>function remove1() {
    var dbl = document.querySelectorAll('#deblist').length;
    var dbla = dbl;
    var elem = document.getElementsByName("deblist["+dbla+"]");
    alert(dbla);
    //var last = debelelast - 1;
    elem.parentNode.removeChild(elem);
  }
  </code></pre>
  
  <p>As an orientation I used to have a look on an example from W3S and Stack. I have also seen that this works:</p>
  
  <pre><code>var elem = document.getElementById("myDiv");
  elem.parentNode.removeChild(elem);
  </code></pre>
  
  <p>But this is random and as you can see I have tried to include this in my code.
  The error I get is: </p>
  
  <blockquote>
    <p>Uncaught TypeError: Cannot read property 'removeChild' of undefined
        at HTMLAnchorElement.remove1 (index.php:179)</p>
  </blockquote>
  
  <p>Where's the problem in my code, where is my thinking wrong?</p>