Skip to content

Instantly share code, notes, and snippets.

@Slackwise
Last active June 30, 2018 01:40
Show Gist options
  • Save Slackwise/ca3b7222cb3b33e881a499044f5b36e2 to your computer and use it in GitHub Desktop.
Save Slackwise/ca3b7222cb3b33e881a499044f5b36e2 to your computer and use it in GitHub Desktop.
Quick function to copy an element's text to the clipboard.
function copyToClipboard(element) {
if (element.select) {
element.select();
document.execCommand('copy');
} else {
let range = document.createRange();
range.selectNodeContents(outputText);
let selection = window.getSelection();
selection.removeAllRanges();
selection.addRange(range);
document.execCommand('copy');
selection.removeAllRanges();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment