title: Having trouble passing an apostrophe or double quote through a clickable link
body: <p>I have some code that receives a string (that might have an apostrophe or double quote in it). On receipt of the string, a link is created to allow the user to utilize the string in an input.</p>
  
  <p>I have created a mockup jsfiddle <a href="https://jsfiddle.net/q8jorw26/1/" rel="nofollow noreferrer">here</a> to demonstrate the problem in a simplified manner. In the real-world version it is much more complicated and the first input and use button don't exist - they are only in the fiddle to simulate the received string.</p>
  
  <p>To test it, enter some text with an apostrophe in the "String with apostrophe" input and click the "Use" button. It will create a link after "Copied String" that says "Use filename". If you click that link, it should put the string into the second input. If there are no apostrophes it's fine, but apostrophes just won't work (you can see the error in the console: <code>SyntaxError: "" string literal contains an unescaped line break</code>).</p>
  
  <p>If I rewrite the <code>$("#usespan").html()</code> line and switch all the <code>"</code> to <code>'</code>, then the apostrophe works, but the double quote doesn't.</p>
  
  <p>How can I get it to work for both <code>"</code> and <code>'</code>?</p>
  
  <p>Thanks!</p>
  
  <p>Jsfiddle code (HTML):</p>
  
  <pre><code>&lt;p&gt;String with apostrophe : &lt;input id="fn"&gt; &lt;input type="button" value="Use" id="usefn"&gt;&lt;/p&gt;
  
  &lt;p&gt;Copied String: &lt;span id="usespan"&gt;&lt;/span&gt;&lt;br&gt;&lt;br&gt;&lt;input id="final"&gt;
  </code></pre>
  
  <p></p></p>
  
  <p>Jsfiddle code (JS):</p>
  
  <pre><code>$("#usefn").on("click", function() {
      var fn = $("#fn").val();
      fn = myHtmlEntities(fn);
      $("#usespan").html(' &lt;a href="javascript:void(0)" onclick="$(\'#final\').val(\' '+fn+'\');"&gt;Use Filename&lt;/a&gt;');
  });
  
  function myHtmlEntities(str) {
     return String(str).replace(/&amp;/g, '&amp;amp;').replace(/&lt;/g, '&amp;lt;').replace(/&gt;/g, '&amp;gt;').replace(/"/g, '&amp;quot;').replace(/'/g,'&amp;apos;');
  }
  </code></pre>