Let’s say we have a DIV container with some content in it. We want to hide that container if the user clicks outside its bounds. Pretty simple solution:
$( document ).mouseup( function( e ) { if( $( "#myDiv" ).has( e.target ).length === 0 ) { $( "#myDiv" ).hide(); } });