Categories
Uncategorized

Copy to clipboard ES6 + Deselect

Code

<script>
const copy = () => {
  const elem = document.getElementById('demo');
  elem.select();
  document.execCommand('copy');
  elem.blur();
}
</script>
<input type="text" id="demo" value="Hello World!" />
<button onclick="copy()">
  Copy
</button>

Demo