JSFiddle - React, Tailwind, and code Playground

HTML

<input type="text" id="textcopy1" class="textcopy1" value="azerty">
<button class="copy" id="copy" data-id="1">Copier</button>
<input type="text" id="textcopy2" class="textcopy2" value="ytreza">
<button class="copy" id="copy" data-id="2">Copier</button>

JavaScript

function copy(id){
    var copyDiv = document.getElementById('textcopy' + id);
    copyDiv.focus();
    document.execCommand('SelectAll');
    document.execCommand("Copy", false, null);
}
document.addEventListener("DOMContentLoaded", function () {
    var elems = document.querySelectorAll('.copy');
	
    Array.prototype.forEach.call(elems, function(elem) {
		elem.addEventListener('click', function() {
    		copy(this.getAttribute("data-id"));
		}, false);
    });
});