Trying to close a datepicker at the same time a dialog is closed

Trying to close a datepicker at the same time a dialog is closed


I tried binding the click event to a form field in a jQuery Dialog box
but it does not work:
$(document).ready(function () {
        $(this.update_ship_date.new_ship_date).attachDatepicker();
        $(".ui-dialog-title:contains('My title text') + .ui-dialog-titlebar-
close").bind('click',
            function () {
                $("form[name=my_form_name] >
input[name=my_date_field]").datepicker('hide');
            }
            );
    }
);
The datepicker shows up as expected when I click the my_date_field
code due to that field's own onclick event, but when I click the close
box on the dialog the datepicker remains visible.
Any idea what I am doing wrong?