Skip to content

Instantly share code, notes, and snippets.

@zachisit
Created March 2, 2018 11:48
Show Gist options
  • Save zachisit/962dd5e3dc7399514cacf868dcdeca74 to your computer and use it in GitHub Desktop.
Save zachisit/962dd5e3dc7399514cacf868dcdeca74 to your computer and use it in GitHub Desktop.
Copy element to clipboard
$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