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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:28:52+00:00 2026-05-28T06:28:52+00:00

Writing some drag&drop code, I’d like to cancel the click events in my mouseup

  • 0

Writing some drag&drop code, I’d like to cancel the click events in my mouseup handler. I figured preventing default should do the trick, but the click event is still fired.

Is there a way to do this?


This doesn’t work:

<div id="test">test</div>
<script>
$("#test").mouseup (function (e) {
  var a = 1;
  e.preventDefault();
});
$("#test").click (function (e) {
  var a = 2;
});
  • 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-05-28T06:28:52+00:00Added an answer on May 28, 2026 at 6:28 am

    I had the same problem and didn’t found a solution either. But I came up with a hack that seems to work.

    Since the onMouseUp handler doesn’t seem to be able to cancel the click on a link with preventDefault or stopEvent or anything, we need to make the link cancel itself. This can be done by writing an onclick attribute which returns false to the a-tag when the drag begins, and removing it when the drag ends.

    And since the onDragEnd or onMouseUp handlers are run before the click is interpreted by the browser, we need to do some checking where the drag ends and which link is clicked and so on. If it ends outside the dragged link (we dragged the link so that the cursor isn’t on the link anymore), we remove the onclick handler in the onDragEnd; but if it ends where the cursor is on the dragged link (a click would be initiated), we let the onclick-handler remove itself. Complicated enough, right?

    NOT COMPLETE CODE, but just to show you the idea:

    // event handler that runs when the drag is initiated
    function onDragStart (args) {
      // get the dragged element
      // do some checking if it's a link etc
      // store it in global var or smth
    
      // write the onclick handler to link element
      linkElement.writeAttribute('onclick', 'removeClickHandler(this); return false;');
    }
    
    // run from the onclick handler in the a-tag when the onMouseUp occurs on the link
    function removeClickHandler (element) {
      // remove click handler from self
      element.writeAttribute('onclick', null);
    }
    
    // event handler that runs when the drag ends
    function onDragEnds (args) {
      // get the target element
    
      // check that it's not the a-tag which we're dragging,
      // since we want the onclick handler to take care of that case
      if (targetElement !== linkElement) {
        // remove the onclick handler
        linkElement.writeAttribute('onclick', null);
      }
    }
    

    I hope this gives you an idea of how this can be accomplished. As I said, this is not a complete solution, just explaining the concept.

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

Sidebar

Related Questions

So I was writing some code today that basically looks like this: string returnString
I'm writing some code in PHP, and I'd like to do something a little
While writing some C code, I decided to compile it to assembly and read
I am writing some code to determine whether a network domain is registered. For
Say I'm writing some ruby code and I want to use the standard Date
I'm writing some semi-portable code and want to be able to detect when I'm
I know that when a drag/drop operation is completed, upon receiving a MouseUp or
Writing some classes for a Framework extension, and I have the following code: public
I´m writing a little audio player in c#. Now I want drag and drop
I'm writing some python code that's supposed to parse a CSV file. Calculate the

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.