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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:59:19+00:00 2026-06-14T21:59:19+00:00

I have an Options button on my webpage. When the user click on that

  • 0

I have an “Options” button on my webpage. When the user click on that button, a little submenu appear.

When I click outside that menu, it closes. So far so good.

My problem is that when I click again on the option button(when the menu is visible), the menu stays open. It should close.

Here’s the code that manage the “click outside” functionality

$j(document).mouseup(function(e) {
   var container = $j('.playlist-menu');

   if (container.has(e.target).length === 0) {
      container.hide();
   }
});

And the event on the button

$j('#options').click(function() {   
    $j('.playlist-menu').toggle();
});

The HTML structure:

<button id="options" class="float-left" title="Options" type="button">
<div class="playlist-menu display-none">
   <ul>
       ...
   </ul>
</div>

I don’t understand why its not closing when I click a second time on the option button, the e.target of that button is not ‘playlist-menu’ so why is the menu not closing??

Thanks

  • 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-14T21:59:20+00:00Added an answer on June 14, 2026 at 9:59 pm

    It’s because when you click on the button, the menu is hidden by the event handler bound to the document, but, the event handler on the option button is fired as well. This triggers the menu to toggle it’s state making it visible.

    To overcome this, check in the event handler bound to the document if the event target is not the options button as well as not an element from the menu.

    So, something like this

    $(document).mouseup(function(e) {
       var container = $('.playlist-menu');
       $target = $(e.target); 
       if (container.has( $target ).length === 0 && !$target.is('#options') ) {
           container.hide();
       }
    });
    

    Hope that makes sense.

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

Sidebar

Related Questions

I have a page with some user selectable options and a button that, when
In my cakephp web page, I have a button that the user clicks and
I have a webpage that displays a table the user can edit. After the
I have a simple webpage that adds & deletes options from a select element
I have a radio button named Choose with the options yes and no. If
I have some options for pricing using radio buttons. When a user selects the
I have a button on a web page that when clicked connects to my
I have a web app (sencha/phonegap) that includes a feature allowing users to click
I have 4 inputfields on my webpage. (2 of those 4 just appear after
I have some very simple forms that will send the user to a specific

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.