title: Unescaping ampersand characters in javascript
body: <p>I'm having trouble properly displaying values that contain escaped characters (i.e. apostrophes are stored as <code>\'</code> and not <code>'</code> and brackets are <code>&amp;gt;</code> and <code>&amp;lt;</code> rather than <code>&gt;</code> and <code>&lt;</code>). </p>
  
  <p>Items stored in my database have the characters (<code>' &lt; &gt;</code>)  escaped to (<code>\' &amp;lt; &amp;gt;</code>), respectively. When I try to dynamically add them to the page with JavaScript, they print out in the escaped form in Firefox, rather than returning to their normal values like in IE (<code>&amp;lt;</code> is being printed to the HTML rather just <code>&lt;</code>).</p>
  
  <pre><code>&lt;html&gt;
      &lt;head&gt;
          &lt;script type="text/javascript"&gt;
           $(document).ready(function() {
              var str = "&amp;gt;";
              $(document.body).html(str);
           });
          &lt;/script&gt;
      &lt;/head&gt;
      &lt;body&gt;
  
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I know that if I simply do a replace, I can print correctly, but by doing so, I'm allowing the injection of HTML code, which is why I escaped the string in the first place.</p>
  
  <p>ADDED:</p>
  
  <p>Firstly, I apologize about the mistakes in my initial post. After closer examination, in the instances where I am using $().html(), the strings are printing correctly. The times where they aren't printing correctly are when I am using code like below.</p>
  
  <pre><code>var str = "&amp;gt;";
  $('#inputField').val(str);
  </code></pre>
  
  <p>In this instance, the text "&gt;" is shown, rather than ">". Is there something I can do to fix this?</p>