title: Copy to clipboard working after clicking twice using javascript
body: <pre><code>function click(){
  var input = document.getElementById('div');
  input.focus();
  document.execCommand('selectAll');
  document.execCommand('copy');
  }
  </code></pre>
  
  <p>The function is executed when clicking on a button:</p>
  
  <pre><code>&lt;button onClick="click();"&gt;copy&lt;/button&gt;
  </code></pre>
  
  <p>Also, I want to copy only the table inside the div element with one
   click but this copies the whole document when clicked twice.</p>