title: Copy button for table with row as id and value
body: <p>I am trying to make a copy button. It only gives an error in Chrome:</p>
  
  <blockquote>
    <p>Uncaught SyntaxError: Unexpected token } </p>
  </blockquote>
  
  <p>I tried lots of different scripts, but none worked. Everything works except the copy button. I even went to the ICT part of our school. They did not have a solution.</p>
  
  <pre><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"&gt;&lt;/script&gt;
  </code></pre>
  
  <p><em>This is the copy script</em><br/></p>
  
  <pre><code>&lt;script&gt;
  function copyToClipboard(element) {
    var $temp = $("&lt;input&gt;");
    $("body").append($temp);
    $temp.val($(element).text()).select();
    document.execCommand("copy");
    $temp.remove();
  }
  
  &lt;/script&gt;
  </code></pre>
  
  <p><em>This is the end of the copy script</em><br/></p>
  
  <pre><code>&lt;?php
  $str1 = "'";
  $str2 = '#';
  ?&gt;
  
  &lt;style&gt;
  table, th, td {
      border: 1px solid black;
      border-collapse: collapse;
  }
  th, td {
      padding: 5px;
      text-align: left;    
  }
  &lt;/style&gt;
  
  &lt;?php
  
  $link = mysqli_connect("localhost", "username", "password", "database");
  
  // Check connection
  if($link === false){
      die("ERROR: Could not connect. " . mysqli_connect_error());
  }
  
  $sqlget = "SELECT      FROM redeem";
  $result = $link-&gt;query($sqlget);
  
  if ($result-&gt;num_rows &gt; 0) {
      // output data of each row
      while($row = $result-&gt;fetch_assoc()) {
  
          echo"&lt;table&gt;";
          echo "&lt;tr&gt;&lt;th&gt;Code: &lt;/th&gt;
  
  
  
  
          &lt;th id=" . $row['code']. "&gt;" . $row['code']. "&lt;/th&gt;
  
  
          &lt;th&gt;Expires: &lt;/th&gt;&lt;th&gt;". $row['expires']."&lt;/th&gt;
          &lt;th&gt;&lt;button onclick='copyToClipboard($str2".$row['code'].")'&gt;&lt;p id=" . $row['code']. "&gt;...&lt;/button&gt;&lt;/th&gt;&lt;/tr&gt;&lt;/table&gt;";
      }
  } else {
      echo "0 results";
  }
  
  ?&gt;
  </code></pre>
  
  <p><em>This code is the working version of the copy button.</em> </p>
  
  <pre><code>&lt;center&gt;
  &lt;p id="p1"&gt;Hello, I'm TEXT 1&lt;/p&gt;
  &lt;p id="p2"&gt;Hi, I'm the 2nd TEXT&lt;/p&gt;&lt;br/&gt;
  
  &lt;button onclick="copyToClipboard('#p1')"&gt;Copy TEXT 1&lt;/button&gt;
  &lt;button onclick="copyToClipboard('#p2')"&gt;Copy TEXT 2&lt;/button&gt;
  
  &lt;br/&gt;&lt;br/&gt;&lt;input class="textBox" type="text" id="" placeholder="Dont belive me?..TEST it here..;)" /&gt;
  &lt;/center&gt;
  </code></pre>
  
  <p>Hope you guys/girls can help me out.</p>