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