I've the following code:
<div class="modal-body">
<div class="text-right fz-sm">
<a href="#" data-action="copy-link">Copy link</a>
</div>
<pre>
https//example.com
</pre>
</div>
Using the link Copy link
, I would like to select the link in <pre>
block and copy it.
Here my try:
$('[data-action="copy-link"]').on('click', function(event) {
event.preventDefault();
$(this).closest('.modal-body').find('pre').select();
document.execCommand('copy');
});
But it doesn't work.
Do you know why please ?
Thanks.