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

  • Home
  • SEARCH
  • 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 8902449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:36:59+00:00 2026-06-15T01:36:59+00:00

I want to be able to bind multiple sequential events using jquery. I want

  • 0

I want to be able to bind multiple sequential events using jquery. I want to do the following:

Click on div1 – aka mousedown event –
now, IF you start moving the mouse while you are STILL pressing down on the mouse, THEN do some function.

What’s the smoothest way of doing this? Just to put an if inside of a .on() call, or is there something simpler?

  • 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-15T01:37:00+00:00Added an answer on June 15, 2026 at 1:37 am

    You can make use of .on() and .off() to achieve this.

    var $div = $("div");
    
    var mousemove = function() { ... };
    
    $div.on({
      mousedown: function() {
        $div.on("mousemove", mousemove);
      },
      mouseup: function() {
        $div.off("mousemove", mousemove);
      }
    });​
    

    Notice that .on() and .off() are the recommended methods to bind and unbind events respectively.

    You can check a live example.


    UPDATE

    Alternatively, you can bind the mouseup event to the document. This way you can detect the release of the mouse even if it doesn’t occur while hovering your element.

    var $document = $(document);
    var $div = $("div");
    
    var mousemove = function() { ... };
    
    $div.mousedown(function() {
      $div.on("mousemove", mousemove);
    })
    
    $document.mouseup(function() {
      $div.off("mousemove", mousemove);
    });​
    

    Also, a shorthand function for it. Let’s call it .drag().

    $.fn.drag = function(fn) {
      var $document = $(document);
      return $(this).each(function() {
        var self = this;
        var $this = $(this);
        var mousemove = function() {
          fn.dragging && fn.dragging.call($this);
        };
        $this.mousedown(function() {
          fn.start && fn.start.call($this);
          fn.dragging && $this.on("mousemove", mousemove);
        });
        $document.mouseup(function() {
          fn.dragging && $this.off("mousemove", mousemove);
          fn.stop && fn.stop.call(self);
        });
      });
    };
    

    $("div").drag({
      start: function() { ... },
      dragging: function() { ... },
      stop: function() { ... }
    });​
    

    You can see it live here.

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

Sidebar

Related Questions

I want to be able to bind a single and double click event to
I want to be able to do this $('.class').bind({'click':'function(){ ... }'}); // note that
I want to be able to bind an event to the axes in high
I'm using LaTeX and BibTeX for an article, and I want to able to
I want to be able to do the following actions with a form submit
I want to be able to add and update certain information. Now it was
Objective I want to be able to run the Applescript to open multiple applications
I want to bind some extra data with a view. I am using tag
Im using a calendar plugin for jQuery, im using the 'selecting multiple dates' demo
I want to build a basic anchor based navigation system using jQuery. I don't

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.