I've been working on a project in which I need to copy a URL to the user's clipboard upon them clicking on a link. I'm aware that there's much documentation about this online, especially with Clipboard JS and this great question, but all of these references seem to show examples of obtaining a value from a button or text field, which is not my use case.
In my case, I have a JQuery variable designed as such;
var destination = $(this).attr('href');
My goal is to take destination
and set it as the text string that will be copied to the clipboard (I have the click event already set up and can confirm it is functioning via alerts).
This is my most recent attempt;
var destination = $(this).attr('href');
var $temp = $("<input>");
$("body").append($temp);
$temp.val(destination).select();
document.execCommand("copy");
$temp.remove();
This, however, has proven largely unsuccessful as nothing is ever copied to the clipboard.