Skip to content

Instantly share code, notes, and snippets.

@SarathSantoshDamaraju
Created January 30, 2019 06:26
Show Gist options
  • Save SarathSantoshDamaraju/6ae61d273ec4a8432949077b374b793e to your computer and use it in GitHub Desktop.
Save SarathSantoshDamaraju/6ae61d273ec4a8432949077b374b793e to your computer and use it in GitHub Desktop.
Copy function value to clipboard with Pure JS
/* ====
ClipboardCopy: This accepts any given string and copys it into clipboard after desired operation.
==== */
function ClipboardCopy(str){
/* Some login */
str = str.toLowerCase();
let convertedStr = str.split(" ").join("-");
/* Copy code */
let $tempInput = document.createElement('INPUT');
document.body.appendChild($tempInput);
$tempInput.setAttribute('value', convertedStr)
$tempInput.select();
document.execCommand('copy');
document.body.removeChild($tempInput);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment