<a href="#" onclick="onDownload(event)">Download</a>
<a href="#" id="fileLink" hidden download="file.txt"></a>
function onDownload(e) {
  e.preventDefault();

  const link = createFile("some text content");
  fileLink.href = link;
  fileLink.click();
}

function createFile(text) {
  const textBlob = new Blob([text], { type: "text/plain" });

  return window.URL.createObjectURL(textBlob);
}

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.