title: JS: remove lastChild only works every second button click
body: <p>I use this code to delete the last item of an <code>&lt;ul&gt;</code> list, but only on the second, fourth, sixth, ... every second click on the button the item gets removed, but every click the message appears. What can I do that the element gets deleted on every click.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>document.getElementsByTagName('input')[0].onclick = function () {
      'use strict';
      var list = document.getElementById('list'), item = list.lastChild;
      list.removeChild(item);
      window.alert("Removed");
  };</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;ul id="list"&gt;
      &lt;li&gt;List item 1&lt;/li&gt;
      &lt;li&gt;List item 2&lt;/li&gt;
      &lt;li&gt;List item 3&lt;/li&gt;
      &lt;li id="child"&gt;List item 4&lt;/li&gt;
      &lt;li&gt;List item 5&lt;/li&gt;
  &lt;/ul&gt;
  &lt;input type="button" value="Delete last"&gt;</code></pre>
  </div>
  </div>
  </p>