Skip to content

Instantly share code, notes, and snippets.

@devded
Last active May 31, 2020 09:41
Show Gist options
  • Save devded/995c8f18e37915d68d42d009e2c99774 to your computer and use it in GitHub Desktop.
Save devded/995c8f18e37915d68d42d009e2c99774 to your computer and use it in GitHub Desktop.
Copy From Text Field Useing Javascript
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Copy From TextFIeld</title>
</head>
<body>
<input id="name" type="text" />
<button id="copy">Copy</button>
</body>
</html>
<script>
function copy() {
var copyText = document.querySelector("#name");
copyText.select();
document.execCommand("copy");
}
document.querySelector("#copy").addEventListener("click", copy);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment