The event you are looking for is .blur()
not .focusout()
.
Edit: click out of #mydiv to hide it:
$("body").click(function(e) {
if ($(e.target).closest("#mydiv").size() == 0) {
$("#mydiv").hide();
}
});
This hides #mydiv if what you clicked doesn't have it as one of it's parents.