This function can be used to detect or trigger another function if mouse has been clicked outside the specific element
$('body').click(function(e){
var clickedOn = $(e.target);
if (!clickedOn.parents().andSelf().is("#elementId")){
//do something / trigger another function
}
});