Skip to content

Instantly share code, notes, and snippets.

@tandibar
Created January 8, 2013 11:17
Show Gist options
  • Save tandibar/4483021 to your computer and use it in GitHub Desktop.
Save tandibar/4483021 to your computer and use it in GitHub Desktop.
This gist describes the issue i have with multiple ZeroClipboards on one page.
<pre id="n1" class="prettyprint">
some code
</pre>
<button class="clip_button" data-clipboard-ref="#n1"><b>Copy To Clipboard</b></button>
<pre id="n2" class="prettyprint">
some other code
</pre>
<button class="clip_button" data-clipboard-ref="#n1"><b>Copy To Clipboard</b></button>
<script type="text/javascript">
$(document).ready(function() {
$(".clip_button").each(function(n, button){
var clip = new ZeroClipboard($(button));
id = $($(button).data('clipboard-ref'));
text = $(id).text();
clip.setText(text);
});
})
</script>
@tandibar
Copy link
Author

tandibar commented Jan 8, 2013

If you click the first button, the clipboard gets populated with "some other code" and not with "some code". The second click on any button clears the clipboard (if i had specified a data-clipboard-text, it would be copied to the clipboard).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment