Referring to this thread: Preview an image before it is uploaded
I would like to know how simply calling reader = new FileReader()
lets FileReader know which file to read.
The thread link posted above works just fine for me, but when I try the following, FileReader()
does not read the input. console.log
returns nothing.
Javascript:
function fileReader(input){
var reader = new FileReader();
reader.onload = function(e){
console.log(e.target.result);
};
}
$(function(){
$('#file').change(function(){
fileReader(this);
});
});
HTML:
<input id="file" type="file">
Why doesn't this work?
Is there a way to manually give FileReader()
which input DOM to read?