Last active
May 31, 2020 09:41
-
-
Save devded/995c8f18e37915d68d42d009e2c99774 to your computer and use it in GitHub Desktop.
Copy From Text Field Useing Javascript
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
<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