Skip to content

Instantly share code, notes, and snippets.

@th3d0g
Created April 23, 2014 21:36
Show Gist options
  • Save th3d0g/11233322 to your computer and use it in GitHub Desktop.
Save th3d0g/11233322 to your computer and use it in GitHub Desktop.
Simulate Click in Javascript
// Simulate mouseclick in native JS
function simClick( el ){
var event = new MouseEvent('click', {
'view': window,
'bubbles': true,
'cancelable': true
});
var canceled = !el.dispatchEvent(event);
if (canceled) {
// A handler called preventDefault.
console.log("click canceled");
} else {
// None of the handlers called preventDefault.
console.log("click successful");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment