js select and copy on click

JavaScript
document.getElementById("copy-text").onclick = function() {
  this.select();
  document.execCommand('copy');
  alert(window.getSelection().toString());
}
Source

Also in JavaScript: