Cancel drag event in JavaScript

Method 1

You can prevent dragging of HTML elements by calling e.preventDefault() method of an event object. This methods stops the browser’s default behavior.

/* Prevent event default behaviour */
window.ondragstart = function(e) {
    e.preventDefault();
};

Note:

Calling e.preventDefault() won’t stop event propagation (or “bubbling up”). If you also want to stop event bubbling use e.stopPropagation().

Leave a Reply

Your email address will not be published. Required fields are marked *