Select all Forms in a div and prevent the default action
<p>I want to Display part of my website in a layover. If the user has no javascript, the layover is displayed as a normal website.</p>

<p>I'm getting the Website with <code>getController</code> and my problem occures in <code>handleLinksAndForm</code>.</p>

<pre><code>$("#Popup &gt; a").click(function(e){
        e.preventDefault();
        getController($(this).attr("href").substr(1),element);
    });
</code></pre>

<p>This works as intended. Whenever a click on a Anchor element in Popover div happens, the default action is prevented and the new website is loaded in the popover.</p>

<pre><code>$("#Popup &gt; form").each(function() {
               alert(this.name);
});
$("#Popup &gt; form").submit(function(e) {
            alert("form");
            e.preventDefault();
            getPostController($(this).attr("action"),$(this).serialize(),element);
            return false;
});
</code></pre>

<p>However, this part does not work. Neither the foreach part nor the .submit().</p>

<p>So my Question is: Whats my mistake? If I use <code>$("form").each(function() {...</code> all forms are recognized, but if I add the extra selector #Popup none is recognized.</p>

<p>Complete Code:</p>

<pre><code>function getController(ctrl,element)
{
    $.get('/service/controller/' + ctrl, function(data){
        handleLinksAndForm(data,element)        
    })
}
function getPostController(ctrl,args,element)
{
    $.post('/service/controller/' + ctrl,args, function(data) {
        handleLinksAndForm(data,element)        
    });
}

function handleLinksAndForm(data,element)
{
    element.html(data);
    element.prepend("&lt;div id=\"popupClose\"&gt;x&lt;/a&gt;");
    centerPopup();
    $("#popupClose").click(function(){
        disablePopup();
   });
    $("#Popup &gt; a").click(function(e){
        e.preventDefault();
        getController($(this).attr("href").substr(1),element);
    });
    $("#Popup &gt; form").each(function() {
           alert(this.name);
        });
    $("#Popup &gt; form").submit(function(e) {
        alert("form");
        e.preventDefault();
        getPostController($(this).attr("action"),$(this).serialize(),element);
        return false;
    });
}
</code></pre>
