Last active
June 30, 2018 01:40
-
-
Save Slackwise/ca3b7222cb3b33e881a499044f5b36e2 to your computer and use it in GitHub Desktop.
Quick function to copy an element's text to the clipboard.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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