$(document).click(function(e){ var e = e || window.event, x = e.srcElement || e.target; if (x != document.getElementById('popup')) $('#popup').fadeOut(); })