title: How to copy text to clipboard from specific table cell in razor view?
body: <p>What I'm trying to do is to copy the text from 'Message' column to clipboard.</p>
  
  <p>And the problem is when I click on a 'Copy message' button, it only copies the first message in the first row.</p>
  
  <p>So is there any solution to this in razor view?</p>
  
  <pre><code>             ....
  @foreach (var item in Model.Customer)
              {
  
                  &lt;tr&gt;
                      &lt;td&gt;
                          @item.id
                      &lt;/td&gt;
                      &lt;td &gt;
                         &lt;span id="messageText"&gt; @item.message&lt;/span&gt;
                      &lt;/td&gt;
                      &lt;td &gt;
                          &lt;button id="copyButton" class="btn btn-default" onclick="copyToClipboard('#messageText')"&gt;Copy Message&lt;/button&gt;
                      &lt;/td&gt;
                      &lt;td &gt;
                          @item.name
                      &lt;/td&gt;                 
  
                      &lt;td &gt;
                          @item.lastName
                      &lt;/td&gt;
  
                  &lt;/tr&gt;
              }
          &lt;/table&gt;
  
  JQuery:
  
    function copyToClipboard(element) {
                  var $temp = $("&lt;input&gt;");
                  $("body").append($temp);
                  $temp.val($(element).text()).select();
                  document.execCommand("copy");
                  $temp.remove();
              }
  </code></pre>