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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:51:49+00:00 2026-05-27T07:51:49+00:00

I am trying to set up a system so that when a user clicks,

  • 0

I am trying to set up a system so that when a user clicks, if that click did not originate from within a specified div then a function should be fired that will do something with that div. Basically more when a user clicks outside of a div i want to hide it, but the problem is that i have a few elements that i want to do this with, so event.stopPropagation doesn’t work very well.

document.onclick = function (e) {
e = !e ? window.event.srcElement : e.target;

if ($('#toppanel div#panel').not(e.id).is(':visible')) { $('.dashboardNav .addWidget').click(); }
if ($('#TrackRibbon').not(e.id).is(':visible')) { $('.dashboardNav #openRibbon').click(); }
if ($('.subnav').not(e.id).is(':visible')) { $('.subnav').hide(); }
}

but this doesn’t work as i want either yet, it does somewhat, but i have multiple .subnav on the page and with this you can open all of them without the others closing.

any ideas on how to accomplish a goal like this would be greatly appreciated, also if i didnt explain well enough just let me know.

  • 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-05-27T07:51:50+00:00Added an answer on May 27, 2026 at 7:51 am

    So this is how i managed to accomplish most of what I wanted. I think with a few tweaks it will be good.

        $(document).click(function (e) {
    
            var closables = ["#TrackRibbon", '#toppanel', '.subnav', '#Mailbox'];
    
            var toggles = ['#openRibbon', '.addWidget', '.topnav > li', '#MailboxToggle'];
    
            var skip = -1;
            e = !e ? window.event.srcElement : e.target;
    
            for (var j = 0; j < toggles.length; j++) {
                if ($(e).parent(toggles[j]).length > 0 || $(e).is(toggles[j])) {
                    skip = j; continue;
                }
            }
    
            for (var k = 0; k < closables.length; k++) {
                $(closables[k]).each(function (i) {
                    if (skip !== k) {
                        if ($(this).has($(e)).length === 0 && $(this).is(':visible')) {
                            $(this).hide();
                        }
                    }
                });
            }
        });
    

    The only part that doesn’t work quite right is the ‘.subnav’ which there can potentially be a lot of. So if anyone has any suggestions to improve let me know.

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

Sidebar

Related Questions

I'm trying to set up a system that displays calendar items from a resource
I am trying to set up a system in which user uploaded files will
I'll try my best to explain how I'm trying to set up this system.
I am trying to set up an automated build system on Windows using Cygwin.
I am trying to set my columns default date time to system datetime. It
I am currently playing with Qt trying to set up a small particle system.
Trying to set it so if a certain condition is met then one of
I'm trying to write a user control that has an ItemsControl, the ItemsTemplate of
I'm trying to add functionality in my program that will allow the user to
I have an ASP.NET website (in C#) that takes in user data and then

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.