$(document).mouseup(function(e) { var element = $(".searchbox-holder"); // if the target element is not expected element if (!element.is(e.target) && element.has(e.target).length === 0) { element.fadeOut("slow"); } });