qw3n
qw3n

Reputation: 6334

Creating a drag event

How would you simulate a dragevent on a particular element? Here is what I tried, but I keep getting a e.dataTransfer is null error when my event handler receives the event.

var event = document.createEvent('DragEvents');
event.initEvent('dragstart', true, false);
document.getElementById('test').dispatchEvent(event);

When I inspect the event from the event handler dataTransfer is a property if you use createEvent('DragEvents') instead of say createEvent('Events') but the property is null.

Upvotes: 3

Views: 5307

Answers (1)

qw3n
qw3n

Reputation: 6334

The document.createEvent('event') is being deprecated. The new method doesn't work because the DragEvent constructor is not meant for actual use.

Check dataTransfer is null when creating drag event programmatically for a similar question .

Upvotes: 2

Related Questions