Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / HTML

ondragend — handling the end of a drag

The ondragend attribute runs JavaScript when a drag operation ends, including cancellation or an unsuccessful drop. It is useful for cleaning up the source element's state, not for confirming that a target accepted data.

Version: WHATWG HTML Living Standard; index snapshot date recorded separately

Syntax

ondragend="JavaScript statements"

ondragend is an event handler content attribute for dragend, permitted on every HTML element. Its value is JavaScript code, not a Boolean value. Within the attribute code, the event parameter provides the event object. The attribute does not itself enable dragging; the example uses draggable="true" for that purpose.

The dragend event is dispatched to the source when the drag operation ends, including cancellation or a rejected drop. Unlike drop, it is not the target's data-acceptance event. It is useful for removing visual dragging indicators. Inspect event.dataTransfer.dropEffect to check the operation's outcome; none means that no operation was performed.

In JavaScript, you can also assign a function to the element.ondragend property or register a listener with element.addEventListener('dragend', handler). The event name is dragend, without the on prefix. Content Security Policy can block code written directly in an attribute; in that environment, use an allowed script with addEventListener.

The example sets the status text to Drag ended regardless of whether dropping succeeds. It does not implement a drop target or data movement.

Examples

<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>ondragend example</title>
<p draggable="true"
   ondragstart="event.dataTransfer.setData('text/plain', 'Sample')"
   ondragend="document.getElementById('status').textContent = 'Drag ended'">
  Drag this text
</p>
<p id="status" role="status">Ready</p>
</html>

Result

Drag ended

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources