0

ZeroClipboard for single click copy. Both the links are giving the same output, rather than different. Demo link HERE

<a id="c101" href="javascript:void(0);">OBJ1</a> &nbsp;&nbsp; 
<a id="x101" href="javascript:void(0);">OBJ2</a>

<script type="text/javascript">
    var dom_obj1 = document.getElementById('c101');
    var dom_obj2 = document.getElementById('x101');

    var clip1 = new ZeroClipboard();
    clip1.glue(dom_obj1);

    clip1.addEventListener( 'dataRequested', function(client, args) {
        client.setText('text1');
    });

    clip1.addEventListener( 'complete', function(client, args) {
        alert('clip1 text: '+args.text);
    });

    var clip2 = new ZeroClipboard();
    clip2.glue(dom_obj2);

    clip2.addEventListener( 'dataRequested', function(client, args) {
        client.setText('text2');
    });

    clip2.addEventListener( 'complete', function(client, args) {
        alert('clip2 text: '+args.text);
    });
</script>
abraj
  • 329
  • 3
  • 14

1 Answers1

2

Give a common class to all these elements, and then make all of them available to ZeroClipBoard :

< a id="c101" class="toBeCopied" href="something">
< a id="c102" class="toBeCopied" href="something else">

Then load them like this :

var clip = new ZeroClipboard($(".toBeCopied"));

PlanetUnknown
  • 3,956
  • 4
  • 49
  • 67
  • I'm marking this answer because it works correctly. Putting a common class on the button. Mainly because $(".class") returns all instances of that class on the webpage – Udit Agarwal May 13 '15 at 12:58