Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

chrome - input["file"] click() does not work when select element 'onchange' triggers it

JsBin - http://jsbin.com/puri/7/edit

What is happening is I am trying to simulate .click() on file["input"] on two scenarios.

  1. Trigger file["input"].click() when 'click' triggered on a button
  2. Trigger file["input"].click() when 'change' triggered on a select

Scenarios 1 & 2 works on Firefox latest. But only 1 works on Chrome latest. What could be causing this problem? Is this how this is supposed to work?

I am on Mac osx 10.9.1

like image 370
Jithin Avatar asked Dec 29 '25 20:12

Jithin


1 Answers

Using the click method does not always trigger handlers as expected, depending on it's origin, target and the browser used. For a more consistent outcome, use dispatchEvent with a custom click Event.

someNode.dispatchEvent(new Event('click'));
like image 53
Paul S. Avatar answered Jan 01 '26 09:01

Paul S.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!