<textarea id="text" hidden>text texttexttexttexttexttexttexttext</textarea>
function myFunction() {
  var copyText = document.querySelector('#text');
  copyText.select();
  document.execCommand("copy");
  copyText.value
}
myFunction();

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.