Created
February 29, 2012 15:11
-
-
Save weivall/1941425 to your computer and use it in GitHub Desktop.
simulateClick
This file contains 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
function simulateClick() { | |
var evt = document.createEvent("MouseEvents"); | |
evt.initMouseEvent("click", true, true, window, | |
0, 0, 0, 0, 0, false, false, false, false, 0, null); | |
var cb = document.getElementById("checkbox"); | |
var canceled = !cb.dispatchEvent(evt); | |
if(canceled) { | |
// A handler called preventDefault | |
alert("canceled"); | |
} else { | |
// None of the handlers called preventDefault | |
alert("not canceled"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment