Created
January 8, 2013 11:17
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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).