Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var copyTextareaBtn = document.querySelector(".click-to-copy");
  2.  
  3. copyTextareaBtn.addEventListener('click', function(event) {
  4.   var copyTextarea = document.querySelector('.click-to-copy-text');
  5.   copyTextarea.focus();
  6.   copyTextarea.select();
  7.  
  8.   try {
  9.     var successful = document.execCommand('copy');
  10.     var msg = successful ? 'successful' : 'unsuccessful';
  11.     console.log('Copying text command was ' + msg);
  12.   } catch (err) {
  13.     console.log('Oops, unable to copy');
  14.   }
  15. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement