Example: https://jsfiddle.net/adzbyt3q/5/
Text should be copied from the trigger element's attribute (data-clipboard-text="text") even when the trigger is in a Bootstrap modal.
Text cannot be copied from the trigger element's attribute (data-clipboard-text="text") when that trigger element happens to be within a Bootstrap modal.
Issue occurs in latest versions of Chrome, Firefox, and Internet Explorer.
I am rather new to Clipboard.JS, so I hope I am not overlooking something. The console records a successful copy (and no error), but nothing appears on the actual clipboard.
In the Fiddle, you'll see that copying from the trigger's own attribute works fine, until you place that trigger in a modal. Also in the Fiddle, this issue does not occur when the trigger is targeting a different element, even when that different element is also within the modal.
I experienced the same bug, but your workaround saved me
Set the container value to the modal's ID:
var clipboard = new ClipboardJS('.btn', {
container: document.getElementById('exampleModal')
});
Thanks @jamesbanogon!
Most helpful comment
Set the container value to the modal's ID: