So when uploading an image via ajax and I come across something like this:
$("input#uploadedfile").on("change", function(){
var file = this.files[0],
});
Assume #uploadedfile is a file type input, is this.files[0] just targeting the first file uploaded? Also is this jQuery doing the exact same thing?:
var file = $(this).get(0).files[0]
The files property of an input element returns a FileList. Assuming this is an input element, this.files[0] returns a File object at the index 0.
$(this).get(0) returns the first element of the jQuery object (remember that every jQuery object is also an array). So $(this).get(0).files[0] is another way of accessing the value of this.files[0].
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With