title: Why are not all elments deleted?
body: <p>I have a strange behavior in my very simple code. I want to <code>remove()</code> all buttons with the class <code>btn</code> from the DOM after a button has been clicked.</p>
  <p>In my function <code>removeAllBtns()</code> I have two console outputs. The correct number of buttons is displayed. But the second element is always not deleted.</p>
  <p>Why is that? I am probably missing something very simple here. Thanks in advance.</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-js lang-js prettyprint-override"><code>let btns = document.getElementsByClassName('btn');
  
  for (var i = 0; i &lt; btns.length; i++) {
    let button = btns[i];
    button.addEventListener('click', function (e) {  
      removeAllBtns();  
    });
  }
  
  function removeAllBtns() {  
    console.log('btns length',btns.length)
    for (let j = 0; j &lt; btns.length; j++) {
      console.log(j, btns[j])
      btns[j].remove();
      
    }
  }</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>.btn{
    color: red;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;button class="btn"&gt;1&lt;/button&gt;   
  &lt;button class="btn"&gt;2&lt;/button&gt;   
  &lt;button class="btn"&gt;3&lt;/button&gt;</code></pre>
  </div>
  </div>
  </p>