HTML5 dragleave fired when hovering a child element
The problem I'm having is that the event of an element is fired when hovering a child element of that element. Also, is not fired when hovering back the parent element again.dragleave
dragenter
I made a simplified fiddle: http://jsfiddle.net/pimvdb/HU6Mk/1/.
HTML:
<div id="drag" draggable="true">drag me</div>
<hr>
<div id="drop">
drop here
<p>child</p>
parent
</div>
with the following JavaScript:
$('#drop').bind({
dragenter: function() {
$(this).addClass('red');
},
dragleave: function() {
$(this).removeClass('red');
}
});
$('#drag').bind({
dragstart: function(e) {
e.allowedEffect = "copy";
e.setData("text/plain", "test");
}
});
What it is supposed to do is notifying the user by making the drop red when dragging something there. This works, but if you drag into the child, the is fired and the isn't red anymore. Moving back to the drop also doesn't make it red again. It's necessary to move completely out of the drop and drag back into it again to make it red.div
p
dragleave
div
div
div
Is it possible to prevent from firing when dragging into a child element?dragleave
2017 Update: TL;DR, Look up CSS as described in @H.D.'s answer below that works in modern browsers and IE11.pointer-events: none;