Question: I spent a good 20 min searching online for this, but couldn't find it. What I want is to to be able to copy a text string on click *without a button*. The text string will be inside a "span" class.

1. User hovers over text string
2. User clicks text string
3. Text string is copied to clipboard

Any help would be greatly appreciated. Thanks!

Answer: 
Try this .[`document.execCommand('copy')`](https://www.google.co.in/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=0ahUKEwi0hMq9toXVAhWMu48KHYpmDlcQFggjMAA&url=https%3A%2F%2Fdeveloper.mozilla.org%2Fen%2Fdocs%2FWeb%2FAPI%2FDocument%2FexecCommand&usg=AFQjCNHKdjvU8Wln15LgsnR0kqUT_CLkxA)

1. click the element and copy the text and post with tmp input element
2. Then copy the text from this input

```js
function copy(that){
var inp =document.createElement('input');
document.body.appendChild(inp)
inp.value =that.textContent
inp.select();
document.execCommand('copy',false);
inp.remove();
}
```

```html
<p onclick="copy(this)">hello man</p>
```
```js
function copy(that){
var inp =document.createElement('input');
document.body.appendChild(inp)
inp.value =that.textContent
inp.select();
document.execCommand('copy',false);
inp.remove();
}
```

```html
<p onclick="copy(this)">hello man</p>
```