Skip to content

Instantly share code, notes, and snippets.

@mohamedmansour
Created July 16, 2011 01:09
Show Gist options
  • Save mohamedmansour/1085872 to your computer and use it in GitHub Desktop.
Save mohamedmansour/1085872 to your computer and use it in GitHub Desktop.
Simulate a click in JavaScript for Google+ Share
function simulateClick(element) {
var clickEvent = document.createEvent("MouseEvents")
clickEvent.initEvent("mousedown", true, true)
element.dispatchEvent(clickEvent);
clickEvent = document.createEvent("MouseEvents")
clickEvent.initEvent("click", true, true)
element.dispatchEvent(clickEvent);
clickEvent = document.createEvent("MouseEvents")
clickEvent.initEvent("mouseup", true, true)
element.dispatchEvent(clickEvent);
}
var elt = document.querySelector('.n-Ja-xg');
simulateClick(elt)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment