jquery dialog custom close button event throws error?

jquery dialog custom close button event throws error?

Hi,
I am using custom close button for a dialog ,

but when click on close button , I'm getting error.
what's wrong with this code ( $(dialogDiv).dialog('close');)

  1. input type="button" id="closeDialog1" class="btnClass" value="Close" style="width: 80px;" />

    var dialogId = 'uniqueName-' + Math.floor(Math.random() * 1000) 

    var dialogDiv = "<div id='" + dialogId + "'></div>";

     

    function loadDialogResult(dialogDiv, result) {

    $(dialogDiv).html(result).dialog({

    modal: true,

    resizable: false,

    title: 'Test',

    closeOnEscape: false,

    open: function () {

    // Hide close button

    $(this).parent().children().children(".ui-dialog-titlebar-close").hide();

    $('#closeDialog1').click(function () {

    debugger;

    $(dialogDiv).dialog('close');

    return false;

    });

    }

    });

    }