function copy() {
var copyText = document.getElementById("link").innerText;
var elem = document.createElement("textarea");
document.body.appendChild(elem);
elem.value = copyText;
elem.select();
document.execCommand("copy");
document.body.removeChild(elem);
alert("Copied the text");
}
#link {
color: blue;
}
<p id="link" onclick="copy()">https://www.spotify.com/us/</p>
Your copy function can be as follows
function copy() {
var copyText = document.getElementById("link").innerText;
var elem = document.createElement("textarea");
document.body.appendChild(elem);
elem.value = copyText;
elem.select();
document.execCommand("copy");
document.body.removeChild(elem);
alert("Copied the text");
}