0

I want to show the file name of input file

$("#imgInp").change(function() {
  $("#filename").text(this.files[0].name);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<label class="file-label">
   <input class="file-input" type="file" name="image" id="imgInp">
   <span class="file-cta">
       <span class="file-icon"><i class="fas fa-upload"></i></span>
        <span class="file-label">image</span>
   </span>
   <span class="file-name" id="filename"></span>
</label>

But it didn't work and give me an error

TypeError: $(...)[0] is undefined
showdev
  • 28,454
  • 37
  • 55
  • 73
John Deck
  • 787
  • 1
  • 12
  • 27

0 Answers0