title: How to escape single quotes or double quotes within jquery's append(), onclick(), alert() at one time?
body: <p>I have a question when i develop my html with javascript.</p>
  
  <p>What finally I want in html is:</p>
  
  <pre><code>&lt;div id="test"&gt;
  &lt;div onclick="alert("it's a test.")"&gt;Show&lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>But in code I want it be realized like this:</p>
  
  <pre><code>&lt;div id="test"&gt;&lt;/div&gt;
  &lt;script&gt;
  var tmp="it's a test.";//be careful, there must be a single quote in this variable
  $('#test').append("&lt;div onclick='alert(\" "+tmp+" \")'&gt;Show&lt;/div&gt;");
  &lt;/script&gt;
  </code></pre>
  
  <p>In firebug it shows:</p>
  
  <pre><code>&lt;div id="test"&gt;
  &lt;div ")'="" test.="" a="" s="" onclick="alert(" it"&gt;Show&lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>So i think it's an escaping problem. But I think it has minimum 3 levels of depth.
  Anyone can help me? Thanks!</p>