title: How to copy and paste HTML/text by JavaScript
body: <p>I want to copy a text that has the CSS class <code>copytext</code>
  and want to paste on the same page that's has CSS class <code>pastehere</code>.</p>
  <p>I am using the following code, but with no result.</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function copyToClipboard(text) {
     const elem = document.createElement('.copytext');
     elem.value = text;
     document.body.appendChild(elem);
     elem.select();
     document.execCommand('.pastehere');
     document.body.removeChild(elem);
  }</code></pre>
  </div>
  </div>
  </p>