Created
March 2, 2018 11:48
-
-
Save zachisit/962dd5e3dc7399514cacf868dcdeca74 to your computer and use it in GitHub Desktop.
Copy element to clipboard
This file contains 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
$copyToClipboard.on('click', function() { | |
copyToClipboard($yourVarName.html()); //in this case, i am copying the html inside a div | |
}); | |
/** | |
* Copy object to Clipboard | |
* @param element | |
*/ | |
function copyToClipboard(element) { | |
var $temp = $("<input>"); | |
$("body").append($temp); | |
$temp.val(element).select(); | |
document.execCommand("copy") | |
$temp.remove(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment