title: Delete button when it's clicked javascript
body: <p>I have some code which is creating a button when a line is added to a chart. When the button is clicked, I want to remove the line from the chart and delete the button. The example can be viewed <a href="http://whichchart.com/" rel="nofollow">here</a>.</p>
  
  <p>To wit, the code that successfully adds the button is:</p>
  
  <pre><code>function getChartData(option){
      var category = $('#category').val();
      var option = option.value;
      var seriesTitle = category+option;
      $.ajax({
          url: "getData.php?action=getChartData",
          type: "GET",
          dataType:"json",
          data: {
              category:category,
              option:option
          },
          success: function(json){
              chart.addSeries({
                  name: seriesTitle,
                  data : []
              });
              $.each(json.Data,function(){   
                  chart.series[chart.series.length-1].addPoint([parseFloat(this.Year), parseFloat(this[option])]);
              });
          }
  
      });
      var series = document.createElement('button');   
      series.onclick = function(){
          removeLine(seriesTitle);
      }
      series.setAttribute('id',seriesTitle);
      series.innerHTML=seriesTitle;
      $('#removeLine').append(series);
  
  } 
  </code></pre>
  
  <p>Then when the button is clicked, this code does not do anything:</p>
  
  <pre><code>function removeLine(seriesTitle){
      chart.series[seriesTitle].remove();
      $(seriesTitle).remove();
  }
  </code></pre>
  
  <p>The error is:</p>
  
  <pre><code>Uncaught TypeError: Cannot call method 'remove' of undefined
  removeLine    oil.js:172
  series.onclick
  </code></pre>
  
  <p>Bonus points for anyone who knows how I call a particular line in highcharts based on a variable e.g. this works:</p>
  
  <pre><code>chart.series[chart.series.length-1].remove();
  </code></pre>
  
  <p>This doesn't:</p>
  
  <pre><code>chart.series[seriesTitle].remove();
  </code></pre>