Skip to content

Instantly share code, notes, and snippets.

@shibbirweb
Created May 5, 2020 06:16
Show Gist options
  • Select an option

  • Save shibbirweb/b509fe94a4aa0bf56909f965c55826ff to your computer and use it in GitHub Desktop.

Select an option

Save shibbirweb/b509fe94a4aa0bf56909f965c55826ff to your computer and use it in GitHub Desktop.
Copy a input field by on click
let referCode = document.getElementById('refer_code');
referCode.select()
try {
const successful = document.execCommand('copy');
const msg = successful ? 'successful' : 'unsuccessful';
alert('Refer code was copied ' + msg);
} catch (err) {
alert('Oops, unable to copy');
}
/* unselect the range */
window.getSelection().removeAllRanges()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment