jQuery Early Binding a Function Possible?
<p>I'm having a small issue with a bit of jQuery:</p>

<pre><code>function getQuickResults(terms) 
{ 
   var url = '/Search/PreviewSearch';

    $.ajax({
        type: "POST",
        url: url,
        data: { terms: terms },
        dataType: "json",
        error: function(xhr, status, error) {
            alert(error);
        },
        success: function(json) {

            $("#quickSearchResults").empty();

            for (var i = 0; i &lt; json.length; i++) {
                var title = json[i].Title;

                $("#quickSearchResults").append($("&lt;span class='quickSearchResult' /&gt;"))
                                        .children(":last")
                                        .append(json[i].Title)
                                        .append("&lt;br /&gt;");
            }

            $("#quickSearchResults").children(":last").css({ 'border-bottom': 'none' });

            if (json.length &gt; 0) {
                $("#quickSearchResults").show();
            }
            else {
                $("#quickSearchResults").hide();
            }
        }
    });
}
</code></pre>

<p>Basically this is my ajax function for a input hint system. On key up, it sends an ajax request to search and returns a small drop down of values.</p>

<p>What I'd like to do, is when a user clicks on one of the spans in the results, it copies that span to the textbox. So I tried this:</p>

<pre><code>        $("#quickSearchResults").append($("&lt;span class='quickSearchResult' /&gt;"))
                                .children(":last")
                                .append(json[i].Title)
                                .append("&lt;br /&gt;")
                                .click(function(evt) {
                                    $("#searchBox").val(json[i].Title);    
                                });
</code></pre>

<p>But this does not work. I tried assigning a variable to json[i].Title and using that instead, but it seems to just always return the title of the last result. I'm thinking it's probably a binding issue, but don't know if there's a way around it. </p>
