Home > Article > Web Front-end > How to Trigger a Hidden File Input Browse Button with jQuery?
Encountering difficulties triggering the browse button of an HTML file input using jQuery? The problem lies within a security restriction that disables file selection functionality when the input is hidden.
To circumvent this limitation, a clever workaround involves positioning the file input element outside the viewport. By setting the CSS properties position: absolute and top: -100px, we effectively move the element off-screen while still maintaining its functionality.
This ingenious hack allows jQuery to trigger the hidden browse button, enabling you to select files without violating security restrictions. As demonstrated in the JSfiddle example provided, this approach works effectively and allows you to seamlessly trigger file selection using jQuery.
The above is the detailed content of How to Trigger a Hidden File Input Browse Button with jQuery?. For more information, please follow other related articles on the PHP Chinese website!