I can dispatch a simple click event (without any optional parameters) with:
var clickEvt = document.createEvent(\"MouseEvents\");
clickEvt.initEvent(\"click\
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
This worked in Chrome@83
const event = new MouseEvent('dblclick', {
bubbles: true,
cancelable: true,
view: window
});
const buttonEl = document.querySelector('#my-button');
buttonEl.dispatchEvent(event);
Just substitute "click"
with "dblclick"
in clickEvt.initEvent
:
var dblclickEvt = document.createEvent("MouseEvents");
dblclickEvt.initEvent("dblclick");
element.dispatchEvent(dblclickEvt);