You need to get the reference to the element you want to copy from within the event handler.
Based on the markup in this copy of the question, the element is the immediate preceding sibling of the button; therefore:
<textarea class="form-control" tabindex="0">something</textarea>
<button type="button" class="copy-button">clickme</button>
<textarea class="form-control"tabindex="3" >something1</textarea>
<button type="button" class="copy-button">clickme</button>
<textarea class="form-control" >something2</textarea>
<button type="button" class="copy-button">clickme</button>
document.addEventListener("click", e => {
let button = e.target;
if (button.tagName !== "BUTTON") { button = button.closest("button"); }
if (!button || !button.classList.contains("copy-button")) { return; }
e.preventDefault();
let textarea = button.previousElementSibling;
while (textarea && textarea.tagName !== "TEXTAREA") {
textarea = textarea.previousElementSibling;
}
if (!textarea) {
alert("Unable to find the textarea to copy!");
return;
}
textarea.select();
textarea.setSelectionRange(0, 99999);
document.execCommand("copy");
alert(`Copied the text: ${textarea.value}`);
});
Demo[
^]