Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to differentiate between click and drag/drop event?

Tags:

People also ask

How do you know if an event is a click event?

An element receives a click event when a pointing device button (such as a mouse's primary mouse button) is both pressed and released while the pointer is located inside the element.

How do mice detect drag?

Even if you move the mouse a tiny bit while clicking, this will say drag . An extra scope like other comments are saying may be needed here.

Is drag a DOM event?

The DragEvent interface is a DOM event that represents a drag and drop interaction. The user initiates a drag by placing a pointer device (such as a mouse) on the touch surface and then dragging the pointer to a new location (such as another DOM element).


I have a problem with element which is both draggable and also has a click event.

$('.drag').mousedown(function() {
    //...
});

$('.class').click(function() {
    //...
)};

<div class="drag class"></div>

When I drag and drop the element, the click event gets fired, too. How to prevent that?


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!