I have 2 pre
blocks, each of them is wrapped with a div and has a copy button.
<div class="code">
<a class="copy">copy</a>
<pre>content of 1st pre</pre>
</div>
<div class="code">
<a class="copy">copy</a>
<pre>content of 2nd pre</pre>
</div>
$('.code').on('mouseenter', function() {
var copy_button = $(this).find('.copy');
var clip = new ZeroClipboard(copy_button, {moviePath: 'ZeroClipboard.swf'});
var content = $(this).find('pre').text();
// at this point, content is always right
// alert(content);
clip.on('mousedown', function(client, args) {
// the content doesn't get updated here
alert(content);
clip.setText(content);
});
});
The problem is, it seems that it always copys the conent of the first-mouseentered-div
.
Say I first
mouseentered div2, and clicked copy, the content (content of 2nd pre
) is copied fine. But then when I try to copy the first pre, the content doesn't get updated, it's still content of 2nd pre
.
What am I doing wrong here? How can I fix this?