document.getElementById("that-element").click();
/** Creates the click on the input */ const clickEvent = document.createEvent( "MouseEvents" ); clickEvent.initEvent( "click", true, false ); document.getElementById("that-element").dispatchEvent( clickEvent );
1 : https://developer.mozilla.org/en-US/docs/Web/API/EventTarget...
2 : http://stackoverflow.com/questions/6367339/trigger-a-button-...
EDIT ( sorry can't reply to you, because HN ) :
Relevant jQuery discussion
3 : https://github.com/jquery/jquery/issues/2476
https://github.com/MediaCrush/MediaCrush/blob/master/scripts...
Here's the code in the jQuery library you linked to that does exactly this as well:
https://github.com/component/file-picker/blob/master/index.j...
The devil is in the details, although obviously your code works for any other clickable elements.
1 : https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement... 2 : http://stackoverflow.com/questions/210643/in-javascript-can-...
1 : https://developer.mozilla.org/en-US/docs/Web/API/EventTarget...
2 : http://stackoverflow.com/questions/6367339/trigger-a-button-...
EDIT ( sorry can't reply to you, because HN ) :
Relevant jQuery discussion
3 : https://github.com/jquery/jquery/issues/2476