title: How to copy contents of a button to clipboard (JS)
body: <p>I want to be able to copy the text of a button to the clipboard. I am able to retrieve the innerText of the button and log it to console but I am not able to add it to the selection and then ultimately add it to the clipboard with 'document.execCommand("copy");'. Any ideas?</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>$(document).ready(function() {
    $('button').on('click', function() {
      var copyText = this.innerText;
      console.log(copyText);
      copyText.select;
      document.execCommand("copy");
      /* Alert the copied text */
      alert("Copied the text: " + copyText);
    });
  });</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"&gt;&lt;/script&gt;
  &lt;div&gt;
    &lt;ul id="test"&gt;
      &lt;li&gt;
        &lt;button class="copy-button" id="button1"&gt;Test1&lt;/button&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;button class="copy-button" id="button2"&gt;Test2&lt;/button&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;button class="copy-button" id="button3"&gt;Test3&lt;/button&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>