You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Secondly, sorry for asking probably basic questions, but I could not work this out.
Basic Example
In this example, I am using Clipboard.js to copy text from the a element, copying the data held in the data-clipboard-text attribute.
That works fine as shown here:
<!DOCTYPE html><htmllang="en"><head><metacharset="UTF-8"><title>Document</title></head><body><aclass="copy_data" data-clipboard-text="that, that and the other">Copy</a><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.4/clipboard.min.js"></script><script>varclipboard=newClipboardJS('.copy_data');;clipboard.on('success',function(e){e.trigger.innerHTML="Copied!"setTimeout(function(){e.trigger.innerHTML="Copy"},1800);e.clearSelection();});</script></body></html>
My Issue
The issue I am struggling with is working out if it is possible to have the copy link still at the top of the page, but for the data that is copied to be defined against a separate element?
For example, instead of this:
<aclass="copy_data" data-clipboard-text="that, that and the other">Copy</a>
Can I do this:
<aclass="copy_data">Copy</a>
With the element containing the data to be copied further down the page - e.g.
<divdata-clipboard-text="that, that and the other"></div>
This might seem like a silly request, but the reason I'm asking is that due to the way the pages are built where I'm using the copy functionality, the copy button needs to be at the top of the page, but at the point that the HTML is written for displaying the copy button, the content to copy has not been generated yet - it won't be generated until further down the page.
Therefore I thought if I could still hold the data to be held in the data-clipboard-text attribute, but still have the copy button at the top of the page, that would solve it.
However, I can't work out how to achieve that result using Clipboard.js. Ideally I would still like to use Clipboard.js for the copy functionality.
Docs: Copy text from another element
I have seen the "Copy text from another element" option from the clipboard.js site:
<!-- Target --><inputid="foo" value="https://github.com/zenorocha/clipboard.js.git"><!-- Trigger --><buttonclass="btn" data-clipboard-target="#foo"><imgsrc="assets/clippy.svg" alt="Copy to clipboard"></button>
However, rather than copying the content from an input element or textarea for example, I wanted to copy the data from the data-clipboard-text attribute of a different element but I wasn't sure how to do that?
Thanks again
The text was updated successfully, but these errors were encountered:
Hi,
Firstly, thank you for a very excellent solution!
Secondly, sorry for asking probably basic questions, but I could not work this out.
Basic Example
In this example, I am using Clipboard.js to copy text from the a element, copying the data held in the data-clipboard-text attribute.
That works fine as shown here:
My Issue
The issue I am struggling with is working out if it is possible to have the copy link still at the top of the page, but for the data that is copied to be defined against a separate element?
For example, instead of this:
Can I do this:
With the element containing the data to be copied further down the page - e.g.
This might seem like a silly request, but the reason I'm asking is that due to the way the pages are built where I'm using the copy functionality, the copy button needs to be at the top of the page, but at the point that the HTML is written for displaying the copy button, the content to copy has not been generated yet - it won't be generated until further down the page.
Therefore I thought if I could still hold the data to be held in the data-clipboard-text attribute, but still have the copy button at the top of the page, that would solve it.
However, I can't work out how to achieve that result using Clipboard.js. Ideally I would still like to use Clipboard.js for the copy functionality.
Docs: Copy text from another element
I have seen the "Copy text from another element" option from the clipboard.js site:
However, rather than copying the content from an input element or textarea for example, I wanted to copy the data from the data-clipboard-text attribute of a different element but I wasn't sure how to do that?
Thanks again
The text was updated successfully, but these errors were encountered: