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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:47:14+00:00 2026-06-05T09:47:14+00:00

Suppose I make a global handler for closing a popup : mouseup_handler: function(item, mouse_is_inside){

  • 0

Suppose I make a global handler for closing a popup :

  mouseup_handler: function(item, mouse_is_inside){
    if(!mouse_is_inside) {
      close_box(item);
      return false;
    };
  },

And I attach it as so :

$("body").bind('mouseup', function(){ mouseup_handler($popup, mouse_is_inside);  });

But let’s say I have two objects that the body needs to be responsible for closing.

Now when I call the close of one of the objects :

 $("body").unbind('mouseup');

Both, or any mouseup handlers attached to the body are removed. I could be more specific and say :

$("body").unbind('mouseup', mouseup_handler() );

But this would still cause the same problem with all mouseup_handler()‘s to be removed.

How can I allow the body to differentiate between the two ( or many ) yet write the most minimal amount of code that can be shared between the two objects for the same handler?

  • 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-05T09:47:16+00:00Added an answer on June 5, 2026 at 9:47 am

    When the event handler is invoked via jQuery, this will refer to the DOM element involved. Thus:

    $('body').bind('mouseup', function() { mouseup_handler( this, mouse_is_inside ); });
    

    (Or as appropriate; it’s hard to tell because you didn’t post very much code.)

    edit wait – if you’re binding to the <body> but you’re doing it as a delegation thing, you should bind with “on” and not “bind”:

    $('body').on('mouseup', 'selector', function() { ... });
    

    By doing that, you ensure that this is bound to the actual event target element and not the <body>. The “selector” should identify the actual elements that you’re interested in.

    To enable and disable event handler behavior, in my opinion it’s much better to do something like add or remove a class name from an element, and to check that in the handler to decide whether to do anything.

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

Sidebar

Related Questions

As a learning technique, i'm suppose to make my own copy of the following
Suppose I want to make a Web application which uses a fixed width and
Suppose the jQuery object of the input is $input. How to make its value
Suppose I have an element called #container-main . How do I make that display:none
Suppose this is my URL route: (r'^test/?$','hello.life.views.test'), How do I make it so that
Suppose there is a C program, which stores its version in a global char*
I am trying to implement a global exception handler in Asp.NET MVC 4 beta.
Suppose I make a 2d array like this: >>> A=np.arange(16).reshape((4,4)) >>> A array([[ 0,
i'm just wondering how are you suppose to put a function within an echo
I supposed to make this type of charts, is it posssible to make through

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.