Here is the ready to go code that converts table to csv
<!DOCTYPE html> <html> <head> <script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"> jQuery.fn.tableToCSV = function() { var clean_text = function(text){ text = text.replace(/"/g, '""'); return '"'+text+'"'; }; $(this).each(function(){ var table = $(this); var caption = $(this).find('caption').text(); var title = []; var rows = []; $(this).find('tr').each(function(){ var data = []; $(this).find('th').each(function(){ var text = clean_text($(this).text()); title.push(text); }); $(this).find('td').each(function(){ var text = clean_text($(this).text()); data.push(text); }); data = data.join(","); rows.push(data); }); title = title.join(","); rows = rows.join("\n"); var csv = title + rows; var uri = 'data:text/csv;charset=utf-8,' + encodeURIComponent(csv); var download_link = document.createElement('a'); download_link.href = uri; var ts = new Date().getTime(); if(caption==""){ download_link.download = ts+".csv"; } else { download_link.download = caption+"-"+ts+".csv"; } document.body.appendChild(download_link); download_link.click(); document.body.removeChild(download_link); }); }; </script> <script> $(function(){ $("#export").click(function(){ $("#export_table").tableToCSV(); }); }); </script> </head> <body> <table id="export_table"> <caption>asdsa</caption> <tr> <th>blah</th> <th>blahs</th> <th>blahss</th> </tr> <tr> <td>blah1</td> <td>blah1</td> <td>blah1</td> </tr> <tr> <td>blah2</td> <td>blah2</td> <td>blah2</td> </tr> </table> <button id="export" data-export="export">Export</button> </body> </html>