After clicking on, .fw-code-copy-buttonI would like to copy the source code from the nearest container.
.fw-code-copy-button-s are created dynamically after the user clicks the selected "View Source" button.
Html for example button:
<span class="fw-code-copy">
<span class="fw-code-copy-button" data-clipboard-text="...">copy</span>
</span>
This is how I fire the click event and determine the source code to copy to the clipboard:
$(document).on("click", ".fw-code-copy-button", function(){
var source = $(this).closest(".fw-code-copy").next("code").text();
});
And this is how clipboard.js fires a copy event
new Clipboard(".fw-code-copy-button", {
text: function(trigger) {
return source;
}
});
Whenever I click anywhere on the website, the following error appears:
Uncaught Error: Missing required attributes, use either "target" or "text"
But first of all I do not want to define the text to copy in data-clipboard-text="..."
and secondly, it data-clipboard-textis defined as "..."a value.
If someone pays a second, I would be very grateful.
[edit] jsFiddle , , UncaughtError , source onClick .
https://jsfiddle.net/2rjbtg0c/1/