$(document).click(function(e) { e = e || window.event; t = e.target || e.srcElement; if (!$(t).is('#block') && !$(t).parents().find('#block').size()==0) { $('#block').hide(); } });