I have a <div>
drop target that I have attached 'drop' and 'dragover' events to. The <div>
contains an image inside an anchor tag (simplistically: <div><a><img /></a></div>
). The child elements of the target seem to block the 'drop' or 'dragover' events from being triggered. Only when the dragged element is over the target, but NOT over its child elements, are both events triggered as expected.
The behavior I would like to achieve is that the 'dragover' and 'drop' events are triggered anywhere over the target <div>
, regardless of the existence of child elements.
Complete HTML/CSS Course 2022 Now HTML 5 came up with a Drag and Drop (DnD) API that brings native DnD support to the browser making it much easier to code up. HTML 5 DnD is supported by all the major browsers like Chrome, Firefox 3.5 and Safari 4 etc.
Most areas of a web page or application are not valid places to drop data. Thus, the default handling of these events is not to allow a drop. Calling the preventDefault() method during both a dragenter and dragover event will indicate that a drop is allowed at that location.
You can disable the pointer-events in CSS for all children.
.targetDiv * { pointer-events: none; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With