Skip to content

Instantly share code, notes, and snippets.

@ayosec
Created May 26, 2011 12:31
Show Gist options
  • Save ayosec/993039 to your computer and use it in GitHub Desktop.
Save ayosec/993039 to your computer and use it in GitHub Desktop.
// Generates a click on the first element returned by document.querySelector("#foo")
// The main idea is to activate all the event handlers asociated to the node
// https://developer.mozilla.org/en/DOM/event.initMouseEvent
// http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-eventgroupings-mouseevents
click_event = document.createEvent("MouseEvents");
click_event.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
document.querySelector("#foo").dispatchEvent(click_event);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment