title: Copy text from <span> to clipboard
body: <p>I've been trying to copy the <code>innerContent</code> of a <code>&lt;span&gt;</code> to my clipboard without success:</p>
  
  <h3>HTML</h3>
  
  <pre><code>&lt;span id="pwd_spn" class="password-span"&gt;&lt;/span&gt;
  </code></pre>
  
  <h3>JavaScript</h3>
  
  <p><em>Function Call</em></p>
  
  <pre><code>    document.addEventListener('DOMContentLoaded', function () {
      document.getElementById('copy').addEventListener('click', copy_password);
  });
  </code></pre>
  
  <p><em>Function</em></p>
  
  <pre><code>function copy_password() {
      var copyText = document.getElementById("pwd_spn").select();
      document.execCommand("Copy");
  }
  </code></pre>
  
  <p>I've also tried:</p>
  
  <pre><code>function copy_password() {
      var copyText = document.getElementById("pwd_spn").textContent;
      copyText.select();
      document.execCommand("Copy");
  }
  </code></pre>
  
  <p>It seems like <code>.select()</code> doesn't work on a <code>&lt;span&gt;</code> element since I get the following error on both:</p>
  
  <p><a href="https://i.stack.imgur.com/qqa1V.png" rel="noreferrer"><img src="https://i.stack.imgur.com/qqa1V.png" alt="enter image description here"></a></p>