$(document).click(function(event){ if($(event.target).closest("img, .dial").length) return; $('.dial').dialog('close'); });