Why $ ('# file-input'). Click () doesn't open file input dialog when called in browser console?

I found this fiddle: http://jsfiddle.net/QVAC7/ that help me open the file input dialog. The idea is simple:

Html

<button id="id">Open</button>
<input id="yourinputname" type="file" name="yourinputname" style="display: none;" />

      

Js

$('#id').on('click', function() {
    $('#yourinputname').trigger('click');
});

      

The code works fine, when I click the button a dialog pops up.

But there is a strange thing, when I entered the same command in the Chrome console, the dialog was not displayed.

$('#yourinputname').trigger('click');

      

he dialog did not show up

Is there a reason for this?

+3


source to share


1 answer


If you use the console to find the jQuery object associated with $('#yourinputname')

inside the JSFiddle, you won't find it because the Result section of the JSFiddle is inside the iFrame that contains this Result code in a secondary document outside of the JSFiddle.



You won't be able to run code from the console this way until you grab the important code from this script, paste it into the page somewhere, and run it yourself.

+2


source







All Articles