title: Remove a button with javascript
body: <p>I am trying to remove a button after it is clicked (the button was created in javascript) and from a different post it said this code would work, but in my console i get the error: </p>
  
  <pre><code>Uncaught TypeError: Cannot read property 'remove' of null
  at HTMLUnknownElement.&lt;anonymous&gt; (RBrOJeLwYgRM:335)
  </code></pre>
  
  <p>Why? Help!
  Code:</p>
  
  <p>Code that is supposedly going to remove elements:</p>
  
  <pre><code>Element.prototype.remove = function() {
      this.parentElement.removeChild(this);
  }
  NodeList.prototype.remove = HTMLCollection.prototype.remove = function() {
      for(var i = this.length - 1; i &gt;= 0; i--) {
          if(this[i] &amp;&amp; this[i].parentElement) {
              this[i].parentElement.removeChild(this[i]);
          }
      }
  }
  </code></pre>
  
  <p>My code which activates the remove function:</p>
  
  <pre><code>else if (PaintBrush.crashWith(Finish)) {
        PaintBrush.y = 50;
        var button = document.createElement("button2");
  button.innerHTML = "Level 2";
        var body = document.getElementsByTagName("body")[0];
  body.appendChild(button);
        GameArena.clear();
        GameArena.stop();
        button.addEventListener ("click", function() {
    startGame2();
          document.getElementById("button-2").remove();
  });
  </code></pre>