To detect a click everywhere except on a specific div and its content in jQuery, here is the code to insert.
The code below will hide the element with the ID #my_div when clicking anywhere else.
This is very useful if your element contains, for example, a login form…
var div_cliquable = $('#ma_div');
$(document.body).click(function(e) {
// Si ce n'est pas #ma_div ni un de ses enfants
if( !$(e.target).is(div_cliquable) && !$.contains(div_cliquable[0],e.target) ) {
div_cliquable.fadeOut(); // masque #ma_div en fondu
}
});

Example of use: closing a submenu by clicking anywhere other than on it.