1

I have this line of code that works when I'm using the paste event:

//This works
document.addEventListener('paste', e => {
  console.log("e.clipboardData.getData('text/plain');", 
               e.clipboardData.getData('text/plain'));
});

But I need to copy and paste with a button so:

//Not Working
jQuery(buttonId).click(e => {
  console.log("e.clipboardData.getData('text/plain');", 
               e.clipboardData.getData('text/plain'));
});
mplungjan
  • 169,008
  • 28
  • 173
  • 236
CommonSenseCode
  • 23,522
  • 33
  • 131
  • 186
  • Looks like a dupe of https://stackoverflow.com/questions/34470272/how-to-paste-on-click-it-works-in-google-docs – mplungjan Jun 20 '17 at 08:18
  • 1
    would also suggest you think about using a library that has implemented the clipboard API with fallbacks and everything that is required to avoid pitfalls.. https://clipboardjs.com/ – Ben Yitzhaki Jun 20 '17 at 08:22

1 Answers1

-2

Try this :

   $("#buttonId").on("click",e => {
   console.log("e.clipboardData.getData('text/plain');", 
               e.clipboardData.getData('text/plain'));
   });

$ symbol is used instead of jQuery keyword , '#' is id selector in jQuery

Mujthaba Ibrahim
  • 207
  • 3
  • 16