Adding generated content to jQuery object which is not bound to the DOM fails
<p>I am trying to dynamically append an HTML-snippet to an existing Element with <code>.append</code>. </p>

<p>Somehow, the HTML String which was created by the script is not appended to the element. </p>

<p>The element which is appended to is not hooked into the DOM at the moment when the snippet is appended. </p>

<p>All of it is encapsulated in a JavaScript function. Here is the code:</p>

<pre><code>append_content = function() {
    var elem = $('&lt;li&gt;&lt;div&gt;some text&lt;/div&gt;&lt;/li&gt;');
    var somecontent = get_content();  // returns a string: '&lt;div&gt;xx&lt;/div&gt;'
    elem.append('&lt;div&gt;bleh1&lt;/div&gt;');
    elem.append(somecontent);
    elem.append('&lt;div&gt;bleh2&lt;/div&gt;');
    console.log(elem);
    return elem;
}
</code></pre>

<p>The log contains all items correctly, like:</p>

<pre><code>&lt;li&gt;
    &lt;div&gt;some text&lt;/div&gt;
    &lt;div&gt;bleh1&lt;/div&gt;
    &lt;div&gt;xx&lt;/div&gt;
    &lt;div&gt;bleh2&lt;/div&gt;
&lt;/li&gt;
</code></pre>

<p>But when im hooking the elem to the DOM later on, the content of the function call is gone.  I.e. it is not visible in the computed source (neither in FireBug nor Chrome development tools). </p>

<p>It looks like this:</p>

<pre><code>&lt;li&gt;
    &lt;div&gt;some text&lt;/div&gt;
    &lt;div&gt;bleh1&lt;/div&gt;
    &lt;div&gt;bleh2&lt;/div&gt;
&lt;/li&gt;
</code></pre>

<p>I am almost convinced that I have some scope issues or something like that here, but I don't get it. There is no error message in the console. Any advice?</p>

<h2>Update</h2>

<p>Indeed, this was a self-made problem. Striipng down the code for an examle to post here made me realize that i called a similar function wihtout the function call mentioned above - silly me. Thanks for all the comments and help.</p>
