Skip to content

Instantly share code, notes, and snippets.

@tsvetomir
Last active June 3, 2021 10:27
Show Gist options
  • Save tsvetomir/0d2a251987c039e03d2251605c525e09 to your computer and use it in GitHub Desktop.
Save tsvetomir/0d2a251987c039e03d2251605c525e09 to your computer and use it in GitHub Desktop.
Copy markup
<button onclick="copyMarkup()">Copy source!</button>
<script>
function copyMarkup() {
const box = document.createElement('textarea');
box.style.position = 'absolute';
box.style.left = '-10000px';
box.setAttribute('cols', '1000');
document.body.appendChild(box);
box.value = document.documentElement.innerHTML;
box.select();
document.execCommand('copy');
e.target.innerHTML = "Success!";
setTimeout(() => document.body.removeChild(box), 100);
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment