JSFiddle - React, Tailwind, and code Playground

by itgoldman

HTML

<h1>hello world</h1>
<div contenteditable="true">you can edit me!</div>
<br>
<button onclick="download_html()">download html</button>

JavaScript

function download(filename, text) {
  var element = document.createElement('a');
  element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
  element.setAttribute('download', filename);

  element.style.display = 'none';
  document.body.appendChild(element);

  element.click();

  document.body.removeChild(element);
}

function download_html() {
  var html = document.body.outerHTML;

  download("my-file.html", html);
}