How to get parent of first jQuery object?
<p>I have the following code which is run at the end of a long table that has several <code>button.enter-match</code> elements:</p>

<pre><code>$("button.enter-match")
.button()
.on('click', function() {
    $("form.enter-match").dialog({
        modal: true,
        height: 'auto',
        width: 200,
        close: function() {
            $("form.enter-match input[name='code']").val('');
        },
        open: function() {
            $("form.enter-match input[name='code']").val('').focus();
        },
        buttons: {
            Set: function() {
                pid = $(this).parents("[data-pid]").data('pid');

                if ($("form.enter-match input[name='code']").val() == '') {
                    alert('Code empty!');

                    return false;
                }

                $.post(
                    request_url,
                    {
                        'action': 'set_match',
                        'pid': pid,
                        'code': $("form.enter-match input[name='code']").val()
                    },
                    function (data) {
                        error_handler(data);

                        if (data['error'] == null) {
                            $("tr#pid-" + pid + " td.code:first div").html('&lt;i&gt;' + $("form.enter-match input[name='code']").val() + '&lt;/i&gt;');
                            $("form.enter-match").dialog('close');
                        }
                    },
                    'json'
                );
            }
        }
    });
});
</code></pre>

<p>The line <code>pid = $(this).parents("[data-pid]").data('pid');</code> does not get the <code>pid</code> data value because <code>form#enter_match</code> is created at the very top of the document to be reused in the code as needed. It therefore will not have a parent with the <code>[data-pid]</code> attribute, however, <code>button.enter-match</code> will. How do I get the value in <code>[data-pid]</code> for this particular <code>button.enter-match</code> from within the <code>$("form.enter-match").dialog()</code> portion of the code?</p>
