I can dispatch a simple click event (without any optional parameters) with:
var clickEvt = document.createEvent("MouseEvents");
clickEvt.initEvent("click");
element.dispatchEvent(clickEvt);
But how do I dispatch a double-click event?
Just substitute "click"
with "dblclick"
in clickEvt.initEvent
:
var dblclickEvt = document.createEvent("MouseEvents");
dblclickEvt.initEvent("dblclick");
element.dispatchEvent(dblclickEvt);
The feauture used in the accepted answer (Event.initEvent()
) has been deprecated.
Instead, use specific event consructors like Event()
So to answer your question, it would be something like :
var doubleClickEvent = new Event('dblclick'); //define double click event
element.dispatchEvent(doubleClickEvent); //trigger double click even
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With