events 

Send to Kindle
home » snippets » javascript » events



Snippets

// Simulating a mouse click.
// Prereq: "element" that needs to be clicked.
// An existing "event"

var clickEvent = document.createEvent("MouseEvent");
clickEvent.initMouseEvent(
    "click",
    true, true,
    window, 0, 
    event.screenX, event.screenY,
    event.clientX, event.clientY, 
    event.ctrlKey, event.altKey,
    event.shiftKey, event.metaKey, 
    0, null);
// simulate a click
element.dispatchEvent(clickEvent);