Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8772911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:09:11+00:00 2026-06-13T18:09:11+00:00

Yes this question has been asked before, but it didn’t solve my problem. So

  • 0

Yes this question has been asked before, but it didn’t solve my problem.

So consider this situation, say i have a div let’s call it container, now this div contains a lot of other various objects like <a>, <img />, <div>, <ul> well you get the point…

Now, user can do stuff in that div, write messages etc… but when he clicks anywhere outside that container element it should dissapear, so that’s simple right?

$(document).on("click", document, function(event){
    if($(event.target).is(".container")) return;
    $(".container").hide();
});    

Well indeed this would work and at the same time not, since it would only check if the target is not container, if you would click say on some button it would dissapear as well, well i could just include every single element in that if statement, oh but in my case it would be a very very long list… so there has to be a better way

And yes i did try to use event.stopPropagation() but it didn’t work, i guess it’s because i’m using on instead of simple click event, please help me out with this…

Also I have setup this fiddle for you: http://jsfiddle.net/nVfJ5/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T18:09:13+00:00Added an answer on June 13, 2026 at 6:09 pm

    Use the closest() method. By definition it starts with the target and works up the tree to find a match. So if the element is the selector it will stop.

    if($(event.target).closest(".container").length) return;
    

    Reference: http://api.jquery.com/closest/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Yes, I know this question has been asked before, but I can't find an
Yes, this question has been asked before, but I don't feel there's been a
Yes, I know this question has been asked a lot of times, but I
Yes, I know this question has been asked dozens of times before. However, when
This question has been asked before but in a slightly different way and I
Yes I know, this question has been asked MANY times but after reading all
This question has been asked before, but non of the answers I found were
Yes, I know this question has been asked 1000 times before... here is the
This exact question has been asked before but I am at my wits end!
I know this question has been asked in a similar fashion before, but I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.