Skip to content

Instantly share code, notes, and snippets.

@TonyDotDev
Last active February 24, 2020 21:21
Show Gist options
  • Save TonyDotDev/b67b02db129028f4428a456060b65674 to your computer and use it in GitHub Desktop.
Save TonyDotDev/b67b02db129028f4428a456060b65674 to your computer and use it in GitHub Desktop.
Copy to clipboard javascript function.
function copyToClipboard(element) {
window.getSelection().removeAllRanges();
const range = document.createRange();
range.selectNode(element);
window.getSelection().addRange(range);
document.execCommand("copy");
window.getSelection().removeAllRanges();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment