Monday, July 09, 2018

Jquery - How to copy text to clipboard on button click

This is how it works:
  1. Creates a temporary hidden text field.
  2. Copies the content of the element to that text field.
  3. Selects the content of the text field.
  4. Executes the command copy like: document.execCommand("copy").
  5. Removes the temporary text field.
You can see a quick demo here:

https://codepen.io/vasashiner/pen/BPBmoj