I\'m toying with jQuery UI, and I like how this demo works: http://jqueryui.com/demos/dialog/#modal-message
However, when a dialog comes up, the only way to close it is
This one will definitely work, since it matters when the overlay is in the dom or not.
$(document).on('click', '.ui-widget-overlay', function(){ $(".ui-dialog-titlebar-close").trigger('click'); });