<clipboard-copy>

A custom element that implements the Clipboard API to copy text content from elements or input values to the clipboard.

Source code & documentation

Demos

Using the value attribute:

<clipboard-copy value="Copy from value attribute"></clipboard-copy>

Using the from attribute:

Copy text content from span element
<clipboard-copy from="[data-element='span']"></clipboard-copy>
<span data-element="span">Copy text content from span element</span>
Copy href from anchor element
<clipboard-copy from="#anchor"></clipboard-copy>
<a id="anchor" href="https://github.com">Copy href from anchor element</a>
<clipboard-copy from="input[type='text']"></clipboard-copy>
<input value="Copy value from input element" type="text">
<clipboard-copy from=".my-textarea"></clipboard-copy>
<textarea class="my-textarea">Copy value from textarea element</textarea>

License

The MIT License (MIT)