Last active
September 8, 2017 00:32
-
-
Save mcansh/d79d5d557188af7097b6eef2a00ddd93 to your computer and use it in GitHub Desktop.
copy to 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
// copy a string | |
function copyToClipboard(string) { | |
const input = document.createElement('input') | |
input.type = 'text'; | |
input.value = string; | |
document.body.appendChild(input); | |
input.select(); | |
document.execCommand('copy'); | |
input.remove(); | |
} | |
copyToClipboard('copied 👌'); | |
// want to copy an elements text content? | |
function copyToClipboard(element) { | |
const string = element.textContent.trim(); | |
const input = document.createElement('input'); | |
input.type = 'text'; | |
input.value = string; | |
document.body.appendChild(input); | |
input.select(); | |
document.execCommand('copy'); | |
input.remove(); | |
} | |
copyToClipboard(document.querySelector('.repository-meta-content')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment