$(document).click(function() { var container = $("#container"); if (!container.is(event.target) && !container.has(event.target).length) { container.hide(); } });