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

Share this post

Leave a Reply

Your email address will not be published. Required fields are marked *