Created
February 23, 2015 07:48
-
-
Save Lochlan/ccbe22e7c5e80b6d7966 to your computer and use it in GitHub Desktop.
This is how you trigger a `change` event on `<input type="file">` with JavaScript — useful for testing!
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
// vanilla JS | |
var event = document.createEvent("UIEvents"); | |
event.initUIEvent("change", true, true); | |
document.querySelector('input[type=file]').dispatchEvent(event); | |
// jQuery | |
$('input[type=file]').trigger('change'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thank you.