JSFiddle - React, Tailwind, and code Playground
HTML
<table id="tableData">
<tr>
<td>blub</td>
<td>tadup</td>
</tr>
<tr>
<td>foo</td>
<td>bar</td>
</tr>
</table>
<a download="table.txt" id="linkDownload" href="">download</a>
JavaScript
(function () {
var textFile = null;
var dataTable = document.getElementById('tableData');
var downloadLink = document.getElementById('linkDownload');
makeDownloadUrl = function (text) {
var data = new Blob([text], {type: 'text/plain'});
// If we are replacing a previously generated file we need to
// manually revoke the object URL to avoid memory leaks.
if (textFile !== null) {
window.URL.revokeObjectURL(textFile);
}
textFile = window.URL.createObjectURL(data);
return textFile;
};
extractData = function (table) {
var data = '', row, col;
for (var i = 0; i < table.rows.length; i++) {
row = table.rows[i];
for (var j = 0; j < Math.min(row.cells.length, 2); j++) {
col = row.cells[j];
data += (j === 1 ? '=' : '') + col.innerText;
}
data += "\n";
}
return data;
}
downloadLink.addEventListener('mouseover', function () {
var myData = extractData(dataTable);
var url = makeDownloadUrl(myData);
console.log(myData);
console.log(url);
downloadLink.href = url;
}, false);
})();