title: Copy to clipboard hidden element
body: <p>I'm trying to understand why this code does not work.</p>
  
  <p>What i'm trying to accomplish is to copy into clipboard the current url, so as a workaround i try to create an hidden input in which i pass the current location, but i have no luck.</p>
  
  <p>here an example of what i've tried so far:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="true">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var copyBtn = document.querySelector('#copy_btn');
  
  copyBtn.addEventListener('click', function () {
   var input = document.createElement('input');
    input.style.display = "none";
    input.setAttribute('value', document.location)
   document.body.appendChild(input);
    // select the contents
    input.select();
    
    document.execCommand('copy');
  }, false);</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;input id="copy_btn" type="button" value="copy"&gt;</code></pre>
  </div>
  </div>
  </p>