Skip to content
Advertisement

javascript stop click event on mousemove

i have a draggable parent with click events on the children. i want to cancel/abort/stop the click event of the child when it’s starting to get dragged, but also don’t want do stop any parent events. Since i don’t use a lot of jQuery, i’d be very thankful for a vanilla javascript solution.

sorry for this newbie question, but i can’t wrap my head around it.

here is what i got so far: JSFiddle

JavaScript

Advertisement

Answer

Detect movement and in that case “prevent” the default click behaviour programmatically using a global variable. We reset the is_moved variable when mousedown, and set it when mousemove.

JavaScript
JavaScript
JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement