Last active
November 19, 2018 12:45
-
-
Save jamilxt/1c7508d446a72eddb8587e6636b3c518 to your computer and use it in GitHub Desktop.
Copy Button Own Inner Text
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
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> | |
<button id="btn" onclick="copyToClipboard('#btn')">Copy Me</button> | |
<script> | |
function copyToClipboard(element) { | |
var $temp = $("<input>"); | |
$("body").append($temp); | |
$temp.val($(element).text()).select(); | |
document.execCommand("copy"); | |
$temp.remove(); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment