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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:55:14+00:00 2026-06-03T22:55:14+00:00

I don’t understand why this is happening. I need to get the objects startPoint

  • 0

I don’t understand why this is happening.

I need to get the objects startPoint which is set on mousedown and the current e.pageY from the mousemove to do some calculations.

var adjustHeight = {
    change: function(e) {
        console.log(this.startPoint)
        console.log(e.pageY);
    },
};

$('#dragger').mousedown(function(e) {
    e.preventDefault();
    
    adjustHeight.startPoint = e.pageY;
    
    $(window).on('mousemove', adjustHeight.change());
    
    $(window).on('mouseup', function() {
        $(window).off('mousemove', adjustHeight.change())
    });
})

However the console prints out the objects startPoint which is what I expect but e.pageY is undefined,
but when I use this line instead:

...
    $(window).on('mousemove', adjustHeight.change);
    
    $(window).on('mouseup', function() {
        $(window).off('mousemove', adjustHeight.change)
    });
...

I get the e.pageY as expected but now the startPoint is undefined. When I checked what this was pointing at it was the DOMWindow.

My question is why is this happening and how would I go about getting both objects properties and the functions e at the same time?

  • 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-03T22:55:15+00:00Added an answer on June 3, 2026 at 10:55 pm
    $(window).on('mousemove', adjustHeight.change());
    

    is executing adjustHeight.change immediately and passing the return value to .on(). Since you are not passing any argument to adjustHeight.change, e will be undefined (and e.pageY won’t be available).


    $(window).on('mousemove', adjustHeight.change);
    

    correctly passes the function to .on, hence later the event object is passed to the handler and you can access e.pageY. But the context (this) is not adjustHeight anymore, it’s the DOM element you bound the handler to. Which is window in this case and window does not have a startPoint property.

    The MDN documentation has an excellent article about this (in general), as does quirksmode.org (with respect to event handlers).


    Solution:

    Pass a new function as handler, which calls adjustHeight.change and passes the event object:

    $(window).on('mousemove', function(event) {
        adjustHeight.change(event);
    });
    

    or bind adjustHeight.change to adjustHeight using $.proxy [docs]:

    $(window).on('mousemove', $.proxy(adjustHeight.change, adjustHeight));
    

    Since you also want to unbind the handler later, you should either assign it to a variable or use a namespaced event [docs].

    Example:

    $(window).on('mousemove.dragger', $.proxy(adjustHeight.change, adjustHeight));
    
    $(window).on('mouseup.dragger', function() {
        // removes both, the mousemove and mousup event handlers
        $(window).off('.dragger');
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Don't quite understand why this copy constructor is not invoked when I build with
Don't understand, if Data.Map is and [] is. I found this out while wondering
Don't ask me why but i can't use this method because I need to
Don't need to do this right now but thinking about the future... What would
Don't dismiss this as a newbie question! It's not, I'm not, I've tried everything,
Don't ask me why but I need to do the following: string ClassName =
I don't know whether this is really possible, but I'm trying my best. If
I don't know if this is a well known 'thing' or something new in
I don't think this is particularly quirky, but in an attempt to control my
For some reason, after submitting a string like this Jack’s Spindle from a text

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.