How set the EventTarget of an Event

Okay – I just had a brainwave and so here’s another answer for you that’s very naughty and might just work. (worked for me 😉

Instead of doing event.target = myObj, you could try:

Object.defineProperty(event, 'target', {writable: false, value: myObj});

I may be wrong here, but I think what happens is that the new target property hides the original one. It doesn’t work the same way as the browser internal event dispatching, and the browser event handling code will almost certainly ignore it, but it might just be enough to fool javascript code that relies on Event.target.

Also, be careful to test it in different browsers, as some browsers might define Event.target as a non-configurable property.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)