CKTIS / HTML
ondrag — handle dragging events
The ondrag attribute contains JavaScript that handles the drag event, dispatched repeatedly at the source during dragging. The attribute does not itself make an element draggable or define a drop target.
Version: WHATWG HTML Living Standard; index snapshot date recorded separately
Syntax
<element ondrag="JavaScript statements"></element>ondrag is an event handler content attribute available on all HTML elements. Its value is JavaScript executed when a drag event is received. Inside the attribute code, the event parameter provides the event object. There is also a corresponding JavaScript property, element.ondrag.
During native dragging, the browser periodically dispatches drag at the source node. This is not an event for every pointer movement; do not assume a fixed frequency. For an ordinary element, set draggable="true" to enable dragging — ondrag alone does not do that.
Distinguish ondragstart (starting), ondrag (ongoing dragging), ondragover (dragging over a potential target), ondrop (dropping), and ondragend (ending). ondrag does not replace drop-target handling. Set drag data in dragstart; during drag, the data store is in protected mode, so the data contents are unavailable.
The example changes the status text to drag received when drag is received. Further events preserve the same text, making the expected result independent of their count. Save the HTML file, open it in a browser, and drag Drag me.
Examples
<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>ondrag example</title>
<p draggable="true"
ondragstart="event.dataTransfer.setData('text/plain', 'demo')"
ondrag="document.getElementById('status').textContent = 'drag received'">Drag me</p>
<output id="status">ready</output>
</html>Result
ready → drag received
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.