The DataTransfer
object is used to hold the data that is being dragged during a drag and drop operation. It may hold one or more data items, each of one or more data types. For more information about drag and drop, see HTML Drag and Drop API.
This object is available from the dataTransfer
property of all drag events
.
DataTransfer()
DataTransfer
object.DataTransfer.dropEffect
none
, copy
, link
or move
.DataTransfer.effectAllowed
none
, copy
, copyLink
, copyMove
, link
, linkMove
, move
, all
or uninitialized
.DataTransfer.files
DataTransfer.items
Read only
DataTransferItemList
object which is a list of all of the drag data.DataTransfer.types
Read only
strings
giving the formats that were set in the dragstart
event. This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
DataTransfer.mozCursor
DataTransfer.mozItemCount
Read only
DataTransfer.mozSourceNode
Read only
Node
over which the mouse cursor was located when the button was pressed to initiate the drag operation. This value is null
for external drags or if the caller can't access the node.DataTransfer.mozUserCancelled
Read only
dragend
event, and is true
if the user canceled the drag operation by pressing escape. It will be false
in all other cases, including if the drag failed for any other reason, for instance due to a drop over an invalid location.DataTransfer.clearData()
DataTransfer.getData()
DataTransfer.setData()
DataTransfer.setDragImage()
Non-standard
This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.
DataTransfer.addElement()
DataTransfer.mozClearDataAt()
DataTransfer.mozGetDataAt()
DataTransfer.mozSetDataAt()
mozSetDataAt()
may only be called with an index argument less than mozItemCount
in which case an existing item is modified, or equal to mozItemCount
in which case a new item is added, and the mozItemCount
is incremented by one.DataTransfer.mozTypesAt()
Every method and property listed in this document has its own reference page and each reference page either directly includes an example of the interface or has a link to an example.
Specification | Status | Comment |
---|---|---|
HTML Living Standard The definition of 'DataTransfer' in that specification. | Living Standard |
mozCursor , mozItemCount , mozSourceNode , mozUserCancelled , addElement() , mozClearDataAt() , mozGetDataAt() , mozSetDataAt() and mozTypesAt are Gecko specific. |
HTML 5.1 The definition of 'DataTransfer' in that specification. | Recommendation | Not included in W3C HTML5 Recommendation |
Desktop | ||||||
---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
Basic support | 4 | Yes | 3.5
|
10 | 12 | 3.1 |
DataTransfer() constructor |
60 | ? | ? | ? | 47 | ? |
addElement
|
No | No | Yes | No | No | No |
clearData |
Yes | ? | Yes | ? | ? | ? |
dropEffect |
Yes | ? | Yes | ? | ? | ? |
effectAllowed |
Yes | ? | Yes | ? | ? | ? |
files |
Yes | ? | Yes | ? | ? | ? |
getData |
Yes | ? | Yes | ? | ? | ? |
items |
4 | Yes | 50 | No | 12 | No |
mozClearDataAt
|
No | No | Yes | No | No | No |
mozCursor
|
No | No | Yes | No | No | No |
mozGetDataAt
|
No | No | Yes | No | No | No |
mozItemCount
|
No | No | Yes | No | No | No |
mozSetDataAt
|
No | No | Yes | No | No | No |
mozSourceNode
|
No | No | Yes | No | No | No |
mozTypesAt
|
No | No | Yes | No | No | No |
mozUserCancelled
|
No | No | Yes | No | No | No |
setData |
Yes | ? | Yes | ? | ? | ? |
setDragImage |
Yes | 18 | Yes | ? | ? | ? |
types |
Yes | ? | Yes | ? | ? | ? |
Mobile | |||||||
---|---|---|---|---|---|---|---|
Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
Basic support | Yes | Yes | Yes | 52 | Yes | No | ? |
DataTransfer() constructor |
60 | 60 | ? | ? | 47 | No | ? |
addElement
|
No | No | No | ? | No | No | No |
clearData |
Yes | Yes | ? | Yes | ? | ? | ? |
dropEffect |
Yes | Yes | ? | Yes | ? | ? | ? |
effectAllowed |
Yes | Yes | ? | Yes | ? | ? | ? |
files |
Yes | Yes | ? | Yes | ? | ? | ? |
getData |
Yes | Yes | ? | Yes | ? | ? | ? |
items |
Yes | Yes | Yes | 50 | Yes | No | ? |
mozClearDataAt
|
No | No | No | ? | No | No | No |
mozCursor
|
No | No | No | ? | No | No | No |
mozGetDataAt
|
No | No | No | ? | No | No | No |
mozItemCount
|
No | No | No | ? | No | No | No |
mozSetDataAt
|
No | No | No | ? | No | No | No |
mozSourceNode
|
No | No | No | ? | No | No | No |
mozTypesAt
|
No | No | No | ? | No | No | No |
mozUserCancelled
|
No | No | No | ? | No | No | No |
setData |
Yes | Yes | ? | Yes | ? | ? | ? |
setDragImage |
Yes | Yes | ? | Yes | ? | ? | ? |
types |
Yes | Yes | ? | Yes | ? | ? | ? |
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer