👀 Live Preview
Drag the box onto the drop zone or release elsewhere. dragend shows dropEffect:
Waiting for dragend…

The ondragend attribute is an inline event handler that runs JavaScript when the dragend event fires. That happens once on the source element when the user releases the mouse button and the drag operation ends—after dragstart and any drag events. It fires whether the drop succeeded or was cancelled. It is part of the HTML Drag and Drop API. The element must have draggable="true" (for most elements). Use ondragend to reset styles, read event.dataTransfer.dropEffect (none, copy, move, link), or finalize state. Do not confuse it with ondrop, which fires on the target. For production sites, prefer addEventListener("dragend", …) over inline handlers.
Inline JS.
Once at end.
none/copy/move.
Source vs target.
Preferred way.
Property API.
ondragend AttributeThe primary purpose of ondragend is to define what happens when a drag operation finishes on the source element. Common uses include resetting opacity or CSS classes applied during the drag, reading event.dataTransfer.dropEffect to know if the drop succeeded, clearing temporary state, or updating a status label. It connects the end of pointer movement to JavaScript cleanup without a full page reload.
Do not confuse ondragend with ondrag or ondrop. dragstart fires once when dragging begins; drag fires many times during movement; dragend fires once when the user releases on the source. drop fires on the drop target only when released over a valid receiver. dragend always runs—even if no drop occurred. Avoid alert() in handlers; update visible status text instead.
After release, event.dataTransfer.dropEffect is none if the drag was cancelled or invalid, or copy, move, or link if a drop succeeded. Production code should use element.addEventListener("dragend", handler).
Set ondragend on a draggable element or assign element.ondragend:
<script>
function handleDragEnd(event) {
var effect = event.dataTransfer.dropEffect;
document.getElementById("status").textContent =
"Drag ended — dropEffect: " + effect;
event.target.style.opacity = "1";
}
</script>
<div draggable="true" ondragend="handleDragEnd(event)">Drag me</div>
<p id="status"></p>draggable="true" on most elements.dragend fires on the source being dragged, not on drop targets.dragstart once, then many drag events, then dragend once on the source.dragend fires whether the drop succeeded or was cancelled.element.ondragend = function(event) { … }.element.addEventListener("dragend", handler).The ondragend attribute accepts a string of JavaScript code:
ondragend="handleDragEnd(event)" — Call a named function with the event object.ondragend="this.style.opacity='1'" — Inline statement to reset styles on release.box.ondragend = (e) => { … } assigns the handler.event.dataTransfer.dropEffect — none, copy, move, or link.const box = document.getElementById("dragBox");
box.draggable = true;
box.addEventListener("dragend", (event) => {
const effect = event.dataTransfer.dropEffect;
document.getElementById("status").textContent =
"Drag ended — dropEffect: " + effect;
event.target.style.opacity = "1";
});
document.getElementById("dragBox").ondragend = function (event) {
console.log("dropEffect:", event.dataTransfer.dropEffect);
};| Event | When it fires | Handler |
|---|---|---|
dragend | Once when user releases on source | ondragend |
dragstart | Once when drag begins | ondragstart |
drag | Repeatedly while source is dragged | ondrag |
drop | Item released on target | ondrop |
dropEffect | none, copy, move, link | Read in dragend handler |
| Always fires? | dragend yes — success or cancel | Unlike drop on target |
| Target | Supported? | Notes |
|---|---|---|
<div>, <span> | Yes | Set draggable="true" |
<img> | Yes | Draggable by default in many browsers |
<a href> | Yes | Links are draggable by default |
<li> | Yes | Common in sortable lists |
<button> | Yes | Needs draggable="true"; add keyboard alternative |
ondragend vs ondrag vs ondrop| Handler | When it fires | Element | Typical use |
|---|---|---|---|
ondrag | Repeatedly while moving | Source | Live feedback during drag |
ondragend | Once when drag ends | Source | Reset styles, read dropEffect, finalize state |
ondrop | Once when released on valid target | Drop target | Accept payload, move DOM node, update data |
Inline ondragend showing dropEffect, dynamic element.ondragend assignment, and comparing dragend vs drop with the full dragstart → drag → dragend sequence.
Drag the box onto the drop zone or release elsewhere. dragend shows dropEffect:
Waiting for dragend…
Run a function when the user releases a draggable element and show dropEffect:
<div draggable="true" ondragend="handleDragEnd(event)">Drag me</div>
<p id="msg"></p>
<script>
function handleDragEnd(event) {
document.getElementById("msg").textContent =
"dragend — dropEffect: " + event.dataTransfer.dropEffect;
event.target.style.opacity = "1";
}
</script>The browser fires dragend on the source element once when the user releases. The inline ondragend attribute calls your cleanup function.
Assign the handler with element.ondragend or addEventListener:
<script>
document.getElementById("dynamicDragElement").ondragend = function (event) {
document.getElementById("log").textContent =
"Dynamic dragend — dropEffect: " + event.dataTransfer.dropEffect;
};
// Or preferred form:
document.getElementById("dynamicDragElement").addEventListener("dragend", handler);
</script>Register the listener once at page load. When the user releases the drag, your handler runs once on the source element.
A full drag sequence fires dragstart, many drag events, then dragend on the source. drop fires only on the target:
box.addEventListener("dragstart", () => { log("dragstart"); });
box.addEventListener("drag", () => { log("drag"); });
box.addEventListener("dragend", (e) => {
log("dragend — dropEffect: " + e.dataTransfer.dropEffect);
});
target.addEventListener("drop", () => { log("drop (target only)"); });Put reset logic in ondragend on the source. Put receive logic in ondrop on the target. Both may run in the same gesture when a drop succeeds.
aria-live regions when dragend resets state so screen reader users get feedback.dragstart fires once on source.
drag fires repeatedly while moving.
dragend fires once on source; read dropEffect.
drop on receiver if valid; dragend still runs.
The dragend event and ondragend handler are part of the HTML Drag and Drop API and supported in all modern browsers — Chrome, Firefox, Safari, and Edge. Touch drag behavior may differ; test on your target devices.
ondragend supportAll major browsers fire the underlying event and honor the ondragend handler attribute.
Bottom line: Universal support for dragend on draggable elements. Set draggable="true" and read dropEffect in your dragend handler.
ondragend.event.dataTransfer.dropEffect.The ondragend attribute runs JavaScript when a draggable element’s drag operation ends and the dragend event fires once on the source. Use it for cleanup, reading dropEffect, and finalizing state—whether or not a drop succeeded.
Prefer addEventListener("dragend", …), set draggable="true", pair with ondragstart and ondrop, and offer keyboard alternatives for accessibility.
ondragendBookmark these before wiring your next event handler.
dragend on source.
EventSuccess or cancel.
Behaviornone/copy/move/link.
APIPreferred.
ModernSource vs target.
Comparedragend event fires — once on the source element when the user releases the mouse and the drag operation ends.dragend always fires on the source when the user releases. Check event.dataTransfer.dropEffect — it is none when no valid drop occurred.ondragend fires on the element being dragged (source). ondrop fires on the drop target when the user releases over a valid receiver.element.addEventListener("dragend", …). Inline ondragend works for simple demos.draggable="true", the user cannot drag the element and ondragend will not run.dragend, it reflects the drop result: none (cancelled), copy, move, or link. Use it to update UI after the drag ends.Practice inline ondragend, addEventListener, dropEffect, and dragend vs drop in the Try It editor.
5 people found this page helpful