title: Remove clicked <li> onclick
body: <p>I have this JavaScript code:</p>
  
  <pre><code>window.onload = init;
  
  function init () {
      var button = document.getElementById("submitButton");
      button.onclick = addItem;
      var listItems = document.querySelectorAll("li");  //assigning the remove click event to all list items
      for (var i = 0; i &lt; listItems.length; i++) {
          listItems[i].onclick = li.parentNode.removeChild(li);
      }
  }
  
  function addItem() {
      var textInput = document.getElementById("item");  //getting text input
      var text = textInput.value;   //getting value of text input element
      var ul = document.getElementById("ul");  //getting element &lt;ul&gt; to add element to
      var li = document.createElement("li");  //creating li element to add
      li.innerHTML = text;    //inserting text into newly created &lt;li&gt; element
  
      if (ul.childElementCount == 0) {  //using if/else statement to add items to top of list
          ul.appendChild(li);       // will add if count of ul children is 0 otherwise add before first item
      }
      else {
          ul.insertBefore(li, ul.firstChild);
      }
  }
  
  function remove(e) {
      var li = e.target;
      var listItems = document.querySelectorAll("li"); 
      var ul = document.getElementById("ul");
      li.parentNode.removeChild(li);        
  }
  </code></pre>
  
  <p>and this HTML:</p>
  
  <pre><code>&lt;body&gt;
       &lt;form&gt;
           &lt;label for="item"&gt;Add an item: &lt;/label&gt;
            &lt;input id="item" type="text" size="20"&gt;&lt;br&gt;
           &lt;input id="submitButton" type="button" value="Add!"&gt;
       &lt;/form&gt;
       &lt;ul id="ul"&gt;
       &lt;/ul&gt;
       &lt;p&gt;
           Click an item to remove it from the list.
      &lt;/p&gt;  
  &lt;/body&gt;
  </code></pre>
  
  <p>What I want to do is remove the whichever <code>&lt;li&gt;</code> element the user clicks, but this doesn't seem to be working and I am unable to find an answer anywhere else online for this specific scenario.  Hoping someone can help me out here and show me what i am missing.</p>