Created
August 3, 2016 19:01
-
-
Save onpaws/f4539f48df874a5ee4611e7ff1a4d32c to your computer and use it in GitHub Desktop.
simulate a click without jQuery (native fire event)
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
| function eventFire(el, etype){ | |
| if (el.fireEvent) { | |
| el.fireEvent('on' + etype); | |
| } else { | |
| var evObj = document.createEvent('Events'); | |
| evObj.initEvent(etype, true, false); | |
| el.dispatchEvent(evObj); | |
| } | |
| } | |
| eventFire(document.getElementById('submitButton'), 'click'); | |
| //see commentary at http://stackoverflow.com/questions/2705583/how-to-simulate-a-click-with-javascript |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment