How do I detect a click outside an element?
Explanation
You can detect a click outside an element by attaching a click event to the document body which will close the window. Also, you have to attach a separate click event. To the container which also means that it will stop propagation to the document body.
$(window).click(function() {
//Hide the menus if visible
});
$('#menucontainer').click(function(event){
event.stopPropagation();
});
Also read, How can I determine the URL that a local Git repository