qw3n qw3n - 5 months ago 72
Javascript Question

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);

When I inspect the event from the event handler
is a property if you use
instead of say
but the property is null.


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 .