Menu

How to reset file input with JavaScript

How to reset file input with JavaScript

An elegant solution to make it possible

Problem

Actually, as suggested by title, things about reset file input in JavaScript are not straightforward: there is not a standardized way to make it working.

Solution

However, here is an elegant way I found to get the goal:

Brief explanation: wrap the input control in a on-the-fly-created <form> and use its reset() method to reset the form which contains the file input. Then remove the form by using unwrap() method.

Demo

You can find a working example on my codePen Profile.

Andrea Paciolla

Da sempre appassionato al mondo della tecnologia, ho messo a frutto il mio amore per la "creazione" nel settore dello sviluppo web. Sono un fervido tifoso della fotografia digitale e delle immagini in movimento.

Latest posts by Andrea Paciolla (see all)

Tag:, ,
andreapaciolla
Share

This is a unique website which will require a more modern browser to work!

Please upgrade today!