Get element from latest append() call
<p>If you use append() to insert a new DOM node, is it possible to move the chain context to the new element?</p>

<p>This sample code illustrates the subject:</p>

<pre><code>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
                      "http://www.w3.org/TR/html4/loose.dtd"&gt;
&lt;html&gt;
&lt;head&gt;&lt;title&gt;&lt;/title&gt;
&lt;script type="text/javascript" 
        src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"&gt;
&lt;/script&gt;
&lt;script type="text/javascript"&gt;&lt;!--
$(function(){
    $("&lt;div&gt;&lt;/div&gt;")
        .appendTo("body")
        .append("&lt;span&gt;Click me&lt;/span&gt;")
        .click(function(){
            alert("Clicked on &lt;" + this.tagName + "&gt;, &lt;SPAN&gt; expected");
        });
});
//--&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>This code attachs an onclick handler to the <code>&lt;div&gt;</code>, but I want it in the new <code>&lt;span&gt;</code>.</p>

<h1>Edit: clarification</h1>

<p>I suppose I was thinking about a direct function such as <code>add()</code> or <code>andSelf()</code> that doesn't break the chain flow so much <code>&lt;:-)</code></p>

<h1>Edit: solution summary</h1>

<p>For the records: there doesn't seem to be a native <code>findAppended()</code> function. These are some of the alternatives:</p>

<p><strong>Alter creation flow:</strong></p>

<pre><code>$("&lt;span&gt;Click me&lt;/span&gt;")
    .appendTo("body")
    .wrap("&lt;div&gt;&lt;/div&gt;")
    .click(function(){
        alert("Clicked on &lt;" + this.tagName + "&gt;, &lt;SPAN&gt; expected");
    });
</code></pre>

<p><strong>Store the new element in a variable:</strong></p>

<pre><code>var span = $("&lt;span&gt;Click me&lt;/span&gt;")
    .click(function(){
        alert("Clicked on &lt;" + this.tagName + "&gt;, &lt;SPAN&gt; expected");
    });
$("&lt;div&gt;&lt;/div&gt;")
    .appendTo("body")
    .append(span);
</code></pre>

<p><strong>Start a new subchain:</strong></p>

<pre><code>$("&lt;div&gt;&lt;/div&gt;")
    .appendTo("body")
    .append(
        $("&lt;span&gt;Click me&lt;/span&gt;")
        .click(function(){
            alert("Clicked on &lt;" + this.tagName + "&gt;, &lt;SPAN&gt; expected");
        })
    );
</code></pre>

<p><strong>Find the new element after creating it:</strong></p>

<pre><code>$("&lt;div&gt;&lt;/div&gt;")
    .appendTo("body")
    .append("&lt;span&gt;Click me&lt;/span&gt;")
    .find("span:last")
    .click(function(){
        alert("Clicked on &lt;" + this.tagName + "&gt;, &lt;SPAN&gt; expected");
    })
    .end(); // Not necessary here, used to illustrate how to continue the chain
</code></pre>

<p>Note: code not tested.</p>
