Skip to content

Instantly share code, notes, and snippets.

@Lochlan
Created February 23, 2015 07:48
Show Gist options
  • Save Lochlan/ccbe22e7c5e80b6d7966 to your computer and use it in GitHub Desktop.
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!
// 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');
@NazimMertBilgi
Copy link

thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment