How to clear files from <input type='file' /> using jQuery or JavaScript

isuru picture isuru · Jan 20, 2017 · Viewed 11.9k times · Source

There are several <input type='file' /> fields in my file and there are no any html forms. I want to clear attached files from particular <input type='file' />. Not from the all fields. I have use $('input').val(""); but it clears all the <input type='file' /> fields. So how I clear the attached files from particular <input type='file' /> field?

Here is the fiddle

Answer

Bandara picture Bandara · Jan 20, 2017

Using JavaScript you can do that as follows.

document.getElementById("#control").value = "";