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 9197931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:10:50+00:00 2026-06-17T22:10:50+00:00

Okay so we all know this way of hiding an element (and multiple elements)

  • 0

Okay so we all know this way of hiding an element (and multiple elements) when clicking outside of it (i.e. element loses focus):

$('document').on('click', function () { $(element).hide(); });

$(element).on('click', function (e) { e.stopPropagation(); /* ka-chow! */ });

Meaning any click event that reaches the document will hide the element, while any click inside the element will not propagate to the document and will not fire the click event.

That’s all nice and well and definitely not news.

However, I have a complex and rich UI. This interface has many elements that require this sort of behavior. Let’s assume only one element needs to get hidden on each event for that matter. Would I need to traverse the whole lot every time, to find the one element I want to hide?

If so what is the most efficient way to do it? Give them all a unique class name? Or store each element’s classname/ID/DOM instance in an array and loop through that every time? Each solution sounds more inefficient than the other to me.

What would you do?

  • 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-17T22:10:51+00:00Added an answer on June 17, 2026 at 10:10 pm

    Assume:

    1. Those elements are show/hide by javascript.

    2. The rule is the later it is showed up, the earlier it is hidden.

    Then I’ll maintain an array to handle it, for example:

    var displayedElements = [];
    
    ...
    
    // called when you want to display an element
    function showUp (ele) {
        // push element into array
        displayedElements.push(ele);
        ...
    }
    
    // called when you want to close the last displayed element
    function closeOneIfAvailable () {
        var len = displayedElements.length;
        if (len > 0) {
            var idx = len - 1;
            hideIt (displayedElements[idx]);
            displayedElements.splice(idx, 1);
        }
    }
    
    // called when you want to hide an element
    function hideIt (ele) {
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, I really know this has GOT to be the long way around doing
Okay, I've been struggling with this all weekend, and I've gotten plenty of help
okay, i have no idea why this isn't working at all. it seems like
Okay, so I have this CSV file of products and all the products have
Okay, I have looked hard for this answer, but all the websites, even the
Okay, I know this i kinda a vague question. But I have a requirement
First of all, yes, I know I'm a newbie, and this is my first
Okay, I know this is going to sound like homework; but here goes any
Okay, this should be really simple, but I have searched all over for the
I know this is a bit of an odd request but it is all

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.