Use jQuery to hide a DIV when the user clicks outside of it

	var eventId = $('class');
       if(eventId == "mobile-menu")
       //For descendants of menu_content being clicked, remove this check if you do not want to put constraint on descendants.
      //Do processing of click event here for every element except with id menu_content


Another simple method

    var container = $("YOUR CONTAINER SELECTOR");

    // if the target of the click isn't the container nor a descendant of the container
    if (! && container.has( === 0) 

Recent Article

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  • Keep your skills sharp, get informed.

    Subscribe to our mailing list and get interesting stuff and updates to your email inbox