Pass data to anonymous Javascript function
<p>I'm trying to query a webservice with jQuery and insert the reply into my html page using jquery templates. My code currently looks like this:</p>

<pre><code>$(function () {
  $('.media-releases h3 div').click(function () {

    var button = $(this);
    if ($(this).hasClass("expand")) {
        $(this).addClass("spinner");
        var params = '{ "year": "' + 2012 + '", "month": "' + 02 + '" }';

        $.ajax({
            type: "POST",
            url: "NewsReleases.asmx/GetNewsReleases",
            data: params,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (response) {
                var result = jQuery.parseJSON(response.d);
                $.get('NewsRelease.htm', function (data) {
                    // The problem is here, button is null. 
                    // I assume I have to create a closure 
                    // but I'm not sure how to do it.
                    var ul = button.parentNode.nextSibling;
                    $.tmpl(data, result).appendTo(ul);
                });

                button.removeClass("spinner");
                button.parents('h3').next().slideDown();
                button.removeClass('expand').addClass('minimise');

            },
            error: function (error) {
                /*Error handling code removed*/
            }
        });

    } else {
        button.parents('h3').next().slideUp();
        button.removeClass('minimise').addClass('expand');
    }
});
</code></pre>

<p>});</p>

<p>How can I make the button variable accessible in the above function so I can append the template to it?</p>
