jQueryUI Dialog

HTML

<div id="myDialog">
    This is the content of my modal dialog box
    <input type="text" id="myTextBox" />
</div>

<button id="clickMe">Click Me</button>

JavaScript

//Set up the dialog box
$("#myDialog").dialog({
    autoOpen  : false,
    modal     : true,
    title     : "A Dialog Box" 
});

//Open the dialog box when the button is clicked.
$('#clickMe').click(function() {
    $("#myDialog").dialog("open");
});
 

$(document).on('click', '#myDialog .ui-dialog-titlebar-close', function(e) { 
e.preventDefault()
    alert('you clicked the x!');
});