-
-
Save svngoku/b075fc0dc9b091222005e87098ae6659 to your computer and use it in GitHub Desktop.
Copy to clipboard
This file contains hidden or 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
| // if code snippet is inside input or textarea tags | |
| function copy() { | |
| var codeSnippet = document.querySelector("#code-snippet"); | |
| codeSnippet.select(); | |
| document.execCommand("copy"); | |
| } | |
| document.querySelector("#copy").addEventListener("click", copy); | |
| // if code snippet is inside pre or code tags | |
| function copy() { | |
| var codeSnippet = document.querySelector("#code-snippet"); | |
| var textarea = document.createElement('textarea'); | |
| textarea.value = codeSnippet.innerText || codeSnippet.textContent; | |
| document.body.appendChild(textarea); | |
| textarea.select(); | |
| document.execCommand("copy"); | |
| document.body.removeChild(textarea); | |
| } | |
| document.querySelector("#copy").addEventListener("click", copy); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment