Note that there are some explanatory texts on larger screens.

plurals
  1. POHTML5 dragleave fired when hovering a child element
    primarykey
    data
    text
    <p>The problem I'm having is that the <code>dragleave</code> event of an element is fired when hovering a child element of that element. Also, <code>dragenter</code> is not fired when hovering back the parent element again.</p> <p>I made a simplified fiddle: <a href="http://jsfiddle.net/pimvdb/HU6Mk/1/" rel="noreferrer">http://jsfiddle.net/pimvdb/HU6Mk/1/</a>.</p> <p>HTML:</p> <pre><code>&lt;div id="drag" draggable="true"&gt;drag me&lt;/div&gt; &lt;hr&gt; &lt;div id="drop"&gt; drop here &lt;p&gt;child&lt;/p&gt; parent &lt;/div&gt; </code></pre> <p>with the following JavaScript:</p> <pre><code>$('#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"); } }); </code></pre> <p>What it is supposed to do is notifying the user by making the drop <code>div</code> red when dragging something there. This works, but if you drag into the <code>p</code> child, the <code>dragleave</code> is fired and the <code>div</code> isn't red anymore. Moving back to the drop <code>div</code> also doesn't make it red again. It's necessary to move completely out of the drop <code>div</code> and drag back into it again to make it red.</p> <p>Is it possible to prevent <code>dragleave</code> from firing when dragging into a child element?</p> <p><strong>2017 Update:</strong> TL;DR, Look up CSS <code>pointer-events: none;</code> as described in @H.D.'s answer below that works in modern browsers and IE11.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload