Skip to content

Instantly share code, notes, and snippets.

@andygock
Created July 24, 2020 14:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andygock/ebeef729b296b97a21e3298c1cf3a662 to your computer and use it in GitHub Desktop.
Save andygock/ebeef729b296b97a21e3298c1cf3a662 to your computer and use it in GitHub Desktop.
JS function to copy string to clipboard in browser
const copy = str => {
const el = document.createElement("textarea");
el.value = str;
document.body.appendChild(el);
el.select();
document.execCommand("copy");
document.body.removeChild(el);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment