title: Create a copy to clipboard button in Sidebar using Google's `Apps Script`
body: <p>Is there a way to create a copy to clipboard button in Sidebar using Google's <code>Apps Script</code>?</p>
  <p>My current code is the following, but the copy button is not working:</p>
  <pre><code>function createCalendarEvent() {
    
      var html = HtmlService.createHtmlOutput()
        .setTitle(&quot;Πληροφορίες για Ημερολόγιο&quot;)
        .setContent('&lt;div&gt;&lt;p id=&quot;item-to-copy&quot;&gt;Test&lt;/p&gt;' + '\n\n&lt;button onclick='+&quot;copyToClipboard()&quot;+'&gt;Copy&lt;/button&gt;&lt;/div&gt;')
        var ui = SpreadsheetApp.getUi(); // Or DocumentApp or SlidesApp or FormApp.
        ui.showSidebar(html);
  }
  
  function copyToClipboard() {
      const str = document.getElementById('item-to-copy').innerText;
      const el = document.createElement('textarea');
      el.value = str;
      el.setAttribute('readonly', '');
      el.style.position = 'absolute';
      el.style.left = '-9999px';
      document.body.appendChild(el);
      el.select();
      document.execCommand('copy');
     
  </code></pre>
  <p>document.body.removeChild(el);
  }</p>
  <p>The second function is javascipt.</p>
  <p>Can you help me please?</p>
  <p><strong>Edit</strong>
  When I click F12 on the browser, I get the following error:</p>
  <pre><code>Uncaught ReferenceError: copyToClipboard is not defined
      at HTMLButtonElement.onclick (userCodeAppPanel:1)
  onclick @ userCodeAppPanel:1
  </code></pre>