copy something to clipboard code example
Example 1: js copy text to clipboard
function copy() {
var copyText = document.querySelector("#input");
copyText.select();
document.execCommand("copy");
}
document.querySelector("#copy").addEventListener("click", copy);
Example 2: js select and copy on click
document.getElementById("copy-text").onclick = function() {
this.select();
document.execCommand('copy');
alert(window.getSelection().toString());
}