How do I make the JS to work for multiple copy buttons? For example, think like 5 posts in a page feed, each with their own copy button. For now it only seems to work for the first button in the page, and other buttons do nothing.
HTML/PHP:
<input type="text" value="<?php the_permalink();?>" id="myInput">
<div class="copytooltip">
<button onclick="myFunction()" onmouseout="outFunc()">
<span class="copytooltiptext" id="myCopyTooltip">Copy to clipboard</span>
Copy text
</button>
</div>
JS:
function myFunction() {
var copyText = document.getElementById("myInput");
copyText.select();
copyText.setSelectionRange(0, 99999);
document.execCommand("copy");
var tooltip = document.getElementById("myCopyTooltip");
tooltip.innerHTML = "Copied: " + copyText.value;
}
function outFunc() {
var tooltip = document.getElementById("myCopyTooltip");
tooltip.innerHTML = "Copy to clipboard";
}