Append and escape
<p>How do I escape before appending?  The following incorrectly appends </p>

<pre><code>'&lt;a here."="" goes="" string"="" title="Some " href="#"&gt;Hello&lt;/a&gt;'
</code></pre>

<p>in the code:</p>

<pre><code>$(function(){
    var t='Some "string" goes here.';
    var jqueryObj=$('#elem');
    jqueryObj.append('&lt;a href="#" title="'+t+'"&gt;Hello&lt;/a&gt;');
});
</code></pre>

<p>REVISED CODE AFTER EDIT</p>

<pre><code>var $accounts=$('#accountList');
$accounts.find('li.accountList').remove();
for (var i = 1; i &lt; data.o.a.length; i++) {
    $accounts.append('&lt;li class="item displayAccount"&gt;'
    +'&lt;input type="checkbox" checked="checked" class="cb" name="accounts[]" value="'+i+'" /&gt;'
    +'&lt;span class="name"&gt;'+data.o.a[i].name
      +((data.o.a[i].e.length)?' &lt;a class="displayError" href="#" title="'+escape(mkList(data.o.a[i].e))+'"&gt;Error&lt;/a&gt;':null)
    +'&lt;/span&gt;'
    +'&lt;/li&gt;');
}
if(data.o.a[0].c.length) {$accounts.append('&lt;li class="item displayAccount"&gt;&lt;input type="checkbox" disabled="disabled" value="0"&gt;&lt;span class="name"&gt;UNASSIGNED&lt;/span&gt;&lt;/li&gt;');}
$accounts.find('a.displayError').displayError();
</code></pre>
