Last active
March 10, 2019 09:26
-
-
Save jermainee/e786644865f1d2b1be0e2dd8b7edadec to your computer and use it in GitHub Desktop.
Copy URL from Input
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
<input type="url" id="copyLinkInput" value="example.com" /> | |
<button id="copyLinkTrigger">Copy link</button> | |
<script> | |
const copyLinkTrigger = document.getElementById("copyLinkTrigger"); | |
const linkInputElement = document.getElementById("copyLinkInput"); | |
copyLinkTrigger.addEventListener("click", event => { | |
event.srcElement.textContent = "Copied!"; | |
linkInputElement.select(); | |
document.execCommand("copy"); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment