The dragover event fires when a dragged item hovers over a target
element. The crucial step is event.preventDefault() – without it the drop on the target will not
work. You can also set dataTransfer.dropEffect (e.g., “move”, “copy”) to indicate to the user what will
happen on drop.
EXAMPLE
RESULT
Drag one of the cards (A–D) into the target area on the right.
On dragstart the dataTransfer (text/plain with the card ID) is set and the
card gets a visual “dragging” cue.
During dragover you call event.preventDefault() (this enables drop) and
suggest a dropEffect:
without modifiers: move,
with Ctrl or ⌘ (Meta): copy.
dragenter/dragleave add/remove a subtle highlight on the target (visual
feedback).
On drop the card:
moves (move) into the target, or
copies (copy) if you hold Ctrl/Meta while dropping.
The “Clear log” button empties the output, and “Reset” refreshes the demo
(returns everything to its initial state).
Card A
Card B
Card C
Card D
Target: hover over me (dragover) and drop me (drop)
Hint: hold Ctrl for suggested copy, otherwise move.
We use cookies for a better user experience and website functionality.