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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:17:50+00:00 2026-05-30T11:17:50+00:00

So I have a dropdown, which I hide and show based on an element

  • 0

So I have a dropdown, which I hide and show based on an element click. However, I also want to hide this dropdown whenever it is visible if I click anywhere else in the document.

This is the dropdown code:

function dropdown(){
    $('#smenubutton').click(function(e){
        var submenu = $(this).find('.submenu');

        if (submenu.is(':visible')){
            submenu.hide();
        }else{
            submenu.show();
        }
    });
}

however, a code like this:

 $(document).click(function(e){
            e.stopPropagation();
            $('.submenu').hide();
        });

will obviously always hide the submenu. both are loaded in document load. I know I am just missing something so simple. Feel free to point me to a duplicate(I have tried searching but can’t find any questions based on my needs) and close this question.

  • 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-30T11:17:52+00:00Added an answer on May 30, 2026 at 11:17 am

    You should check if e.target is the submenu and hide the submenu only if it’s not (in this case i check if it has the class submenu)

    $(document).click(function(e){
                if($(e.target).hasClass("submenu")){ 
                  $('.submenu').hide();
                }
            });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have <ul> <li class=section-title>HEADER which triggers dropdown</li> <li><a href=element_one>element one</a></li> <li><a href=element_one>element one</a></li>
I want to click a <select> but stop it to show his dropdown list
I have a simple jquery function which I use to show/hide some divs. The
I have a custom TreeView for which I'd like to hide the ImageList dropdown
I have dropdown menu..which is dynamic.. How can get value of the last item
I have a dropdown list (FK) which I would like to set and display
I am having a project which will have country dropdown at the top to
I have a little dropdown menu similar <select> , which contolled from external js-function.
I have a UserControl A which contains a dropdown a placeholder At runtime the
I have a website on with MVC, which has a dropdown in the masterpage.

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.