Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save shibbirweb/153e609fdbd9ee103600e58bf6c7da00 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