B
B
butize2020-04-15 11:31:43
css
butize, 2020-04-15 11:31:43

How to clear input type=file field?

https://jsfiddle.net/katyamsko/vhkxoa7q/12/ - put the code here.
Hello! Can you please tell me why the input type=file field is not being cleared? I make a label and input and link them. I hide the input, because I don’t need the standard one, but I style the label. But I need to clear the field on the button when the user has uploaded the file. I looked for ways, but they do not work for me (

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
twobomb, 2020-04-15
@butize

H
hzzzzl, 2020-04-15
@hzzzzl

the input is cleared, it’s just that the label changes separately when you select a file, and when you clear the input, you don’t clean the label
if you remove all styling and leave only this JS, then you can see that everything works

document.querySelector('.remove').addEventListener('click', function() {
  document.querySelector('input[type=file]').value = '';
}, false);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question