The HTMLElement.click() method simulates a mouse click on an element
https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement.click
The HTML 5 Specification states-
element.click() Acts as if the element was clicked.
The click() method must run the following steps:
If the element is a form control that is disabled, abort these steps.
Run synthetic click activation steps on the element.
See the click method specification
The behaviour itself will depend on the element click on, the default behaviour by the user agent (browser) for a click on that element type (generally nothing, with the exception of input types) and any custom events the developer has added for the element.
To simulate a click event-
var domElement = document.getElementById(elementId);
if (domElement && typeof(domElement.click) === "function")
{
domElement.click();
}
For some examples of how different elements respond (and that you can even trigger click event handlers by simulating the click event) see http://jsfiddle.net/pwdst/KGgXq/ for some examples.
In answer to your specific point/question regarding the file input, the HTML 5 specification for the element does state "activation behaviour" for a input element with type "file". This includes-
Display a prompt to the user requesting that the user specify some
files. If the multiple attribute is not set, there must be no more
than one file selected; otherwise, any number may be selected. Files
can be from the filesystem or created on the fly, e.g. a picture taken
from a camera connected to the user's device.
The specification states that this should only happen if the element is not disabled or read-only.
#myfile.click()isn't valid...click()?clickmethod ofinput type="file", a dialog should be opened.