click button and copy its value to an input field code example
Example 1: js select and copy on click
document.getElementById("copy-text").onclick = function() {
this.select();
document.execCommand('copy');
alert(window.getSelection().toString());
}
Example 2: jquery copy to clipboard
document.execCommand("copy");