title: Copy element content to clipboard on click using jquery
body: <p>Is there a way to copy to clipboard an element content by clicking on other element?</p>
  
  <p>I saw lots of related problems, but I don't like the approach of using function.</p>
  
  <p>since the data is from the database.</p>
  
  <p>here's my sample code.</p>
  
  <p><a href="https://codepen.io/gerryl1991/pen/ZrRXwo" rel="nofollow noreferrer">CODEPEN</a></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(){
    $(".click .copy").click(function(){
        $(this).closest("click").find("span").text();
        document.execCommand("Copy");
    });
   });</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>.click{
    padding: 10px;
  }
  .click .copy{
  background-color: rgba(0,0,0,.8);
  padding: 3px;
  border-radius: 12px;
  position: absolute;
  margin-top: -2px;
  width: 80px;
  cursor: pointer;
  color: #f7cc83;
  display: none;
    text-align: center;
  }
  .click:hover .copy{
   display: block;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;div class="click"&gt;
    &lt;div class="copy"&gt;copy text&lt;/div&gt;
    &lt;span&gt;copy this text 1&lt;/span&gt;
  &lt;/div&gt;
  &lt;div class="click"&gt;
    &lt;div class="copy"&gt;copy text&lt;/div&gt;
    &lt;span&gt;copy this text 2&lt;/span&gt;
  &lt;/div&gt;
  &lt;div class="click"&gt;
    &lt;div class="copy"&gt;copy text&lt;/div&gt;
    &lt;span&gt;copy this text 3&lt;/span&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>