treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Clear a File Input

Last updated on:

You can just clone it and replace it with itself, with all events still attached.

var input = $("#control");

function something_happens() {
    input.replaceWith(input.val('').clone(true));
};


        
			
View Comments

Comments

  1. Sreekanth
    Permalink to comment#

    Click on Clear button for more than 1 time does n’t work.

  2. Not working…

  3. Tobias
    Permalink to comment#

    Same here, the example works only the first time.
    Selecting a different file puts “changed” to the console.log but clicking on the “clear” link does nothing.
    Win7/Chrome 26

Leave a Comment

Use markdown or basic HTML and be nice.