<button data-id="XXX1" class="copy-button">Copy</button>
<div id="XXX1"></div>
<button data-id="XXX2" class="copy-button">Copy</button>
<div id="XXX2"></div>
<button data-id="XXX3" class="copy-button">Copy</button>
<div id="XXX3"></div>
<textarea id="textarea-el"></textarea>
document.querySelectorAll('.copy-button').forEach(btn => {
btn.addEventListener('click', () => {
const id = btn.dataset.id;
const text = document.getElementById(id).textContent;
document.getElementById('textarea-el').value = text;
});
});