2 つpre
のブロックがあり、それぞれが div でラップされ、コピー ボタンがあります。
<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);
});
});
問題は、常にのコンテンツをコピーしているように見えることですfirst-mouseentered-div
。
マウスでdiv2first
に入り、コピーをクリックすると、コンテンツ ( content of 2nd pre
) が正常にコピーされます。しかし、最初のプレをコピーしようとすると、コンテンツは更新されず、まだcontent of 2nd pre
.
ここで何が間違っていますか?どうすればこれを修正できますか?