Skip to content

Instantly share code, notes, and snippets.

@jermainee
Last active March 10, 2019 09:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jermainee/e786644865f1d2b1be0e2dd8b7edadec to your computer and use it in GitHub Desktop.
Save jermainee/e786644865f1d2b1be0e2dd8b7edadec to your computer and use it in GitHub Desktop.
Copy URL from Input
<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