I am wondering how to use the Clipboard.js functionality when dynamically adding content using jQuery. Currently my code is as follows which works if static on a page loaded without jQuery:
<div class="snippet"><div id="title">TEXT TO COPY</div></div>
When I load this as a dynamic addition using jQuery I am doing the following which doesn't work:
var content = '<div class="snippet"><div id="title">TEXT TO COPY</div></div>';
$('#profilesTable').append(content);
I have tried:
new Clipboard('.snippet');
after loading the content but that doesn't work, as well as what was mentioned on the Clipborad.js page for advanced usage:
new Clipboard('.snippet', {
target: function(trigger) {
return trigger.nextElementSibling;
}
});
This doesn't seem to work either. What am I missing after I dynamically add my content?
I have looked at Understanding non-functioning Clipboard.js implementation with AJAX but this does not provide the answer.
Thanks