This is how it works:
https://codepen.io/vasashiner/pen/BPBmoj
- Creates a temporary hidden text field.
 - Copies the content of the element to that text field.
 - Selects the content of the text field.
 - Executes the command copy like: 
document.execCommand("copy"). - Removes the temporary text field.
 
https://codepen.io/vasashiner/pen/BPBmoj