clipboard.js

A modern approach to copy & cut to the clipboard. No Flash. No dependencies. Just 1kb.

Install

You can get it using bower:

bower install clipboard --save

Or download as ZIP.

Usage

First, you need to instantiate it using a selector. This selector corresponds to the trigger element (usually a <button>).

new Clipboard('.btn');

The easiest way to copy some content to the clipboard, is to include a value attribute in your trigger element.

<button class="btn" value="lorem ipsum">Copy</button>

Another way of doing it is to copy the content from an <input> or <textarea>. You can do that by adding a for attribute in your trigger element. The value you include in this for attribute needs to match another's element id attribute.

<input id="target" value="Lorem ipsum">
<button class="btn" for="target">Copy</button>

Browser Support

Chrome logo Firefox logo Internet Explorer logo Opera logo Safari logo
42+ ✔ 41+ ✔ 9+ ✔ 29+ ✔

License

MIT License © Zeno Rocha

Description
✂️ Modern copy to clipboard. No Flash. Just 3kb gzipped 📋
https://clipboardjs.com Readme 8.1 MiB
Languages
JavaScript 99.1%
TypeScript 0.6%
Shell 0.3%