CKTIS / JavaScript
DragEvent.dataTransfer — drag data
DragEvent.dataTransfer exposes the DataTransfer object for a drag event. Access to its payload depends on the operation's phase; a script-created event can return null.
Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support
Syntax
event.dataTransfer // DataTransfer | nullDragEvent.dataTransfer is a read-only property returning DataTransfer or null. The browser attaches an object to native drag events. new DragEvent("drop") defaults to null for dataTransfer; the constructor accepts an explicit object. The reference is read-only, not the object's entire contents.
In a native drag operation, you can write data with setData() during dragstart and read it with getData() during drop, but you cannot modify it during drop. For the other events in that operation, the drag data store is in protected mode: you can inspect formats through types, but getData() returns an empty string. files exposes files, and items exposes data items.
Creating a dragover event in script and supplying it with a new DataTransfer does not put that store in protected mode. getData() can still return data written with setData().
To let an ordinary element accept a drop, cancel dragover using preventDefault(). For a native drag, read the payload synchronously in the drop handler before access to the store ends. Copy needed values before asynchronous work.
This is a browser API defined by HTML, not a feature of a particular ECMAScript edition. Availability in Node 24 does not establish browser support. The example requires the DragEvent and DataTransfer constructors; creating an event in script does not start native dragging.
Examples
(() => {
const transfer = new DataTransfer();
transfer.setData("text/plain", "CKTIS");
const event = new DragEvent("drop", { dataTransfer: transfer });
const emptyEvent = new DragEvent("drop");
console.log(event.dataTransfer === transfer);
console.log(event.dataTransfer.getData("text/plain"));
console.log(emptyEvent.dataTransfer === null);
})();Result
true CKTIS true
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.