DEV Community

Discussion on: 24 modern ES6 code snippets to solve practical JS problems

Collapse
 
marko035 profile image
Marko • Edited

22 can be shortened a lot. Here is shorter version.

const listener = (e: ClipboardEvent) => {
  e.clipboardData.setData('text/plain', text);
  e.preventDefault();
};

document.addEventListener('copy', listener);
document.execCommand('copy');
document.removeEventListener('copy', listener);
Collapse
 
madza profile image
Madza • Edited

Thanks for your point. I first started with clipbard.js for that (3kb gzipped) :)