qw3n qw3n - 1 year ago 122
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.

Answer Source

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 .

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download