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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:23:22+00:00 2026-06-09T21:23:22+00:00

I am having some trouble with a button which when clicked, activates a popup

  • 0

I am having some trouble with a button which when clicked, activates a popup menu. When the menu is popped up, if you click the button again, the popup goes away. But if you re-click the button, the menu doesn’t show up UNTIL I click somewhere outside of the button. I believe the issue lies with the one click event along with the selector being “html” which it binds the event to. Any ideas?

GetDropDownButton: function (option, thisId) {
        var menu = $('#' + option);
        // shows the popup
        menu.show();

        setTimeout(function () {
            // idea is to click anywhere to allow popup to close
            $('html').one('click', function () {
                // hides the popup
                menu.hide();
            });
        }, 100);
    },
  • 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-09T21:23:24+00:00Added an answer on June 9, 2026 at 9:23 pm

    I think you are experiencing problems with the bubbling effect of javascript events. When you click on a button, his click event gets triggered first, then the one of its parent, all the way up the DOM to the document root. I think the solution for you might be to apply the stopPropagation function from jQuery. I set up a small example here: http://jsfiddle.net/FF73h/

    Since it’s so little code I’ll past it here as well:
    HTML

    <div class="popup">
        popup!
    </div>
    <button class="btn-toggle">on/off</button>​
    

    JS

    // make the button show/hide the popup
    $('.btn-toggle').click(function(e) {
        $('.popup').toggle(); 
        // prevent the handler for the document to be called as well, wich would hide again
        e.stopPropagation();  
    });
    // make the popup close when clicked anywhere in the document
    $(document).click(function() {
        $('.popup').hide();
    });
    // optional: prevent the popup from closing when clicked inside it, stops the ducoment event from beeing called
    $('.popup').click(function(e) {
        e.stopPropagation();            
    });
    

    I think the code should explain itself. If not, feel free to let me know.

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

Sidebar

Related Questions

I having some trouble figuring this problem out where I have one button which
I am having some trouble getting a button clicked after submitting a form using
I'm having some trouble committing records to the database. When I click a button,
I am having some trouble with my toast context for my submit button. I've
I'm trying to add a UIButton to a UIView, but am having some trouble
I am having trouble with making my button perform a click after a postback.
im having some trouble with the radio button list in ASP.net, for some reason
I am using a SearchCtrl with a dropdown menu and I'm having some trouble
I'm having some trouble with sleep(). I have 10 UIButtons which are connected to
Having some trouble with R's garbage collection, when passing objects to C++. We have

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.