Skip to content

Instantly share code, notes, and snippets.

@hereswhatidid
Created December 10, 2020 15:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hereswhatidid/8782d9ab482fbf7adae502ba8dbda562 to your computer and use it in GitHub Desktop.
Save hereswhatidid/8782d9ab482fbf7adae502ba8dbda562 to your computer and use it in GitHub Desktop.
Copy field value to clipboard
let copyBtn = document.getElementById( 'copyBtn' ),
copyField = document.getElementById( 'fieldID' );
copyBtn.addEventListener( 'click', function( e ) {
e.preventDefault();
copyField.focus();
copyField.select();
document.execCommand( 'copy' );
alert( 'Field copied!' );
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment