title: How to export data from table to csv file using jquery
body: <p>I'm trying to export from a data table into a CSV file. Here is my whole function. It downloads a file, but it shows the whole code for the table and not separating any of the data out. When I say whole code I mean everything within 'table /table'</p>
  
  <pre><code>function displayDataTable(index){
  $("#pageOverlay").empty();
      html = "&lt;div id='volumeChartDiv'&gt;&lt;h4&gt;Data Table&lt;/h4&gt;&lt;table id='dataTable' class='table table-bordered table-striped dataTable' role='grid'&gt;&lt;thead&gt;&lt;tr role='row'&gt;&lt;th&gt;header1&lt;/th&gt;&lt;th&gt;header2&lt;/th&gt;&lt;th&gt;header3&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;cell1-1&lt;/td&gt;&lt;td&gt;cell1-2&lt;/td&gt;&lt;td&gt;cell1-3&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bell2-1&lt;/td&gt;&lt;td&gt;bell2-2&lt;/td&gt;&lt;td&gt;bell2-3&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;fell3-1&lt;/td&gt;&lt;td&gt;fell3-2&lt;/td&gt;&lt;td&gt;fell3-3&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;input type='button' value='Close' onclick='closeOverlay()'&gt;&amp;nbsp;&amp;nbsp;&lt;input type='button' id='exportDataTable' value='Export Table'&gt;&lt;/div&gt;";
    $("#pageOverlay").html(html);
  // export data function    
    $("#exportDataTable").click(function (e) {
        window.open('data:application/vnd.ms-excel,' + $('.dataTable').html());
        e.preventDefault();
  });
     openOverlay();
  }
  </code></pre>