You define li
to be:
li = doc.getElementsByTagName('li')[0]
But there are no li
elements to begin with, so doc.getElementsByTagName('li')[0]
returns undefined
.
You'll need to move that event handler into the other callback:
list.appendChild(item); // get <ul>, and add the variable 'item'.
item.onclick = function () {
list.removeChild(item);
};