Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the filelist object when a file is selected Jquery

When dragging and dropping a file into <div> for getting the filelist object i used var files=e.originalEvent.dataTransfer.files; but when selecting a file from the upload window i do not know what to use.

Check this jsfiddle.

What should I use to get the filelist from the <input type="file">?

like image 656
harikrishnan.n0077 Avatar asked Jan 27 '26 04:01

harikrishnan.n0077


1 Answers

any jQuery object have it's DOM element accessed using [], for example

$('input[type=file]')[0].files;

To your fiddle, it would be:

var files = this.files;

no need for jQuery in this case, because of the change event

See the updated fiddle http://jsfiddle.net/qdJ2T/1/

like image 180
pocesar Avatar answered Jan 30 '26 16:01

pocesar



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!