clipboard copy js

for copying things to the clipboard, like the click to copy.

Basic Usage

Include the script

<script src="js/clipboard.min.js"></script>

add a field to copy to the clipboard

<input id="clipme" value="">

add a button or link to copy it and bind it to the id clipme

<a class='btn btn-primary' data-clipboard-target="#clipme">Copy to Clipboard</a>

Well this is a bit of a fail it seems to be targeting the script src from above... hmm.

Ah its cos i forgot to start the plugin... doh!

Also have to add this selector to the elements that are going top be running the copy and paste

new Clipboard('.btn');

Ok it works now, it should highlight the text in the field above when you click the button, it copied to my clipboard ok.

Seems like a bit of effort to get working. But its not too bad once you remember to:

  1. add the main script clipboard.min.js
  2. add a field or element to copy with correct #id
  3. add the button with the data binding data-clipboard-target="#id"
  4. initialise the script and target the button new Clipboard('#id');

thats the basic usage, for more detailed usage go to the official site





Other Items in js


This is my test area for webdev. I keep a collection of code snippits here, mostly for my reference. Also if i find a good site, i usually add it here.