I have a certain scenario where I’m using click to insert a div and then mousedown on that div for dragging it around. I have bound the click to the parent container, and the mousedown on the div itself. But when I mousedown on the div, it fires the click on the parent as well, hence inserting multiple divs instead of dragging the already added div!
Is there a way to solve this issue? I can’t unbind click, since I need to add 2 divs using the click, and then bind mousedown on these.
Update: I’m using selector.on(event, handler) type of binding.
Try this way.
event.stopPropagationdoes not stop the click event from firing after mousedown. Mousedown and click events are not related to each other.Update:
Mouse events are triggered like this:
mousedown
click
mouseup
If mousedown is triggered, the
mousedownFiredvariable will be set totrue. Then in the click event, it willreturn(i.e. not continue processing the click event), and themousedownFiredvariable will be reset to false, so future click events will fire normally. Not going to consider two mousedown or two click events.