简体   繁体   中英

jQuery Clipboard Plugin not working on dynamically added elements

I'm using the jQuery Clipboard plugin.

JS:-

jQuery(document).ready(function($) {
    jQuery('.the_clipboard').clipboard({
        path: 'path/to/jquery.clipboard.swf',
        copy: function() {
            return jQuery(this).parent().find('.copyable').text();
        }
    });
});

HTML:

<td>
    <span class="copyable">TO_BE_COPIED</span>
    <button class="the_clipboard btn btn-sm" style="margin-top:-2px;">
        <span class="glyphicon glyphicon-paperclip"></span>
    </button>
</td>    

When new td elements are added then the text doesn't get copied to the clipboard, when the_clipboard is clicked.

Your code to call the clipboard plugin on the .the_clipboard elements is only run on page load. You will need to run it again on the td elements that are added dynamically.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM