Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

e.dataTransfer is undefined

I have a problem with my drag and drop item, when i drag got an error: "e.dataTransfer is undefined"

drag function

dragstart: function(e) {
    e.dataTransfer.effectAllowed = 'move';
    e.dataTransfer.dropEffect = 'move';
    e.dataTransfer.setData('application/json', index);
    element.addClass('dragging');
}

Someone know where is the problem?

like image 1000
Bastien Bast Weber Avatar asked Aug 27 '13 09:08

Bastien Bast Weber


People also ask

What is e DataTransfer?

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.

What is setData in javascript?

getData() The DataTransfer. getData() method retrieves drag data (as a string) for the specified type. If the drag operation does not include data, this method returns an empty string. Example data types are text/plain and text/uri-list .

How to set dragged data?

Get the dragged data with the dataTransfer. getData() method. This method will return any data that was set to the same type in the setData() method. The dragged data is the id of the dragged element ("drag1")


2 Answers

Add dataTransfer prop explicitly:

e.dataTransfer = e.originalEvent.dataTransfer;
like image 65
alex.mironov Avatar answered Oct 22 '22 03:10

alex.mironov


In jquery you have to use it like this, it will work:

e.originalEvent.dataTransfer.dropEffect = 'move';
like image 14
Muhammad Shahid Avatar answered Oct 22 '22 05:10

Muhammad Shahid