Created
April 23, 2014 21:36
-
-
Save th3d0g/11233322 to your computer and use it in GitHub Desktop.
Simulate Click in Javascript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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