I use this code to delete the last item of an <ul>
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.
document.getElementsByTagName('input')[0].onclick = function () {
'use strict';
var list = document.getElementById('list'), item = list.lastChild;
list.removeChild(item);
window.alert("Removed");
};
<ul id="list">
<li>List item 1</li>
<li>List item 2</li>
<li>List item 3</li>
<li id="child">List item 4</li>
<li>List item 5</li>
</ul>
<input type="button" value="Delete last">
`. Check out [this Plunker](http://plnkr.co/edit/6aaN2Cq7JAJiJWvOpaff?p=preview) to see the empty text nodes logged out to the console
– scniro May 15 '15 at 14:57