I am trying to change the label text for a file input field to the name of the file, however I get the following error in my console:
Uncaught TypeError: Cannot read property 'files' of undefined
Here's the HTML and JQuery:
<div class="custom-file">
<label class="custom-file-label text-left" for="customFile" id="file">Choose file</label>
<input type="file" class="custom-file-input" id="customFile">
</div>
<script type="text/javascript">
$('#customFile').change(function() {
var i = $(this).prev('label').clone();
var file = $('customFile')[0].files[0].name;
$(this).prev('label').text(file);
});
</script>
I'm still learning JQuery, so any help is greatly appreciated!