1

This is currently the way I trigger events and it had worked fine for me but now I need to use the event target and I realized it's not being correctly copied:

Element.prototype.trigger=function(eventname,ev){
    var e;
    if(ev){
        console.log(ev.target); //target is the element under the mouse
        e = new window[ev.constructor.name](eventname,ev);
    } else e = new Event(eventname);
    this.dispatchEvent(e); //e.target===element
    return this;
}

When my function is called, event.target is always the same element (it should return the element under the mouse)

element.on("mousedrop",function(e){
    console.log("drop",e.target,e.currentTarget); //e.target===element
});

How can I clone the event including all of its properties? This is obviously not a regular object, it wouldn't be recognized as an event and there are some properties with only a getter to just copy them into a new event object.

Here is an example, try to put draggable into droppable:

https://jsfiddle.net/uxfaprmk/3/

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
shuji
  • 7,369
  • 7
  • 34
  • 49

0 Answers0