.click() Event dont get executed
<p>I have a link on my site which opens a modal dialog with the login form. I use AJAX to send the login data to the server and but somehow, the .click() event doesn't work. I guess its because I load the html with .html().</p>

<p>Here's the code:</p>

<pre><code>$('#loginLink').click(function(e) {
            e.preventDefault();
            $('&lt;div id="loginContainer" title="Login"&gt;&lt;/div&gt;')
            .html('&lt;?php echo str_replace(array("\r\n", "\r", "\n"), "", $this-&gt;element("ajax/login")); ?&gt;')
            .dialog({
                modal: true,
                resizable: false,
                position: 'top'
            });
        });
        $('#UserLoginForm input[type=submit]').click(function() {
            e.preventDefault();

            var form = $('#UserLoginForm').serialize();

            $.ajax({
                type: 'POST',
                url: '/login',
                dataType: 'json',
                data: form,
                beforeSend: function(XMLHttpRequest) {
                    $("#loginContainer .ajaxloader").show();
                },
                success: function(data) {
                    var message = $("#loginContainer &gt; .flashMessage");

                    if(data.status == 'success') {
                        location.href = '/account';
                    } else {
                        message.text(data.msg);
                        message.show();
                    }
                },
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                    $('#loginContainer .ajaxloader').hide();
                    $('#loginContainer &gt; .flashMessage').text('There was an error.').show();
                },
                complete: function(XMLHttpRequest) {
                    $("#loginContainer .ajaxloader").hide();
                }
            });
            return false;
        });
</code></pre>

<p>This part loads the content from a file:</p>

<pre><code>&lt;?php echo str_replace(array("\r\n", "\r", "\n"), "", $this-&gt;element("ajax/login")); ?&gt;
</code></pre>

<p>And outputs:</p>

<pre><code>&lt;div class="flashMessage fail"&gt;&lt;/div&gt;&lt;form action="/login" controller="users" id="UserLoginForm" method="post" accept-charset="utf-8"&gt;&lt;div style="display:none;"&gt;&lt;input type="hidden" name="_method" value="POST"/&gt;&lt;/div&gt;&lt;div class="input text required"&gt;&lt;label for="UserEmail"&gt;E-Mail&lt;/label&gt;&lt;input name="data[User][email]" style="width: 267px;" maxlength="64" type="text" id="UserEmail"/&gt;&lt;/div&gt;&lt;div class="input password required"&gt;&lt;label for="UserPassword"&gt;Password&lt;/label&gt;&lt;input name="data[User][password]" style="width: 267px;" type="password" id="UserPassword"/&gt;&lt;/div&gt;&lt;div class="submit"&gt;&lt;input type="submit" value="Login"/&gt;&lt;/div&gt;&lt;/form&gt;&lt;div class="ajaxloader"&gt;&lt;img src="/img/icons/ajax-loader.gif" alt="" /&gt;&lt;/div&gt;&lt;div class="clear" style="line-height: 8px;"&gt;&amp;nbsp;&lt;/div&gt;
</code></pre>

<p>Everything works fine except the .click() part to send the AJAX request :/ Im not that good in Javascript, so I don't know what exactly the error is.</p>
