I have made a website that contains many different text parts that can be copied to the clipboard.
I used the script below for this.
Is there an alternative that doesn't require you to use an ID in the font tag? Because they are long pages of text and many text parts can be copied to the clipboard, it is annoying to use a new ID everytime. Everything is mixed up and additions are made regularly.
function copyElementText(id) {
var text = document.getElementById(id).innerText;
var elem = document.createElement("textarea");
document.body.appendChild(elem);
elem.value = text;
elem.select();
document.execCommand("copy");
document.body.removeChild(elem);
}
Copy this text 4Copy this text 2
<font id="text1" onclick="copyElementText(this.id)">Copy this text 1</font>
<p>
<font id="text2" onclick="copyElementText(this.id)">Copy this text 2</font>
<p>
<font id="text3" onclick="copyElementText(this.id)">Copy this text 3</font>
<p>
<font id="text4" onclick="copyElementText(this.id)">Copy this text 4</font>
<p>