Reset or clear the value of fileupload control using jquery

This example will shows you how to reset/clear the value of asp.net fileupload control or html input type file using jquery.

Syntax:
control.replaceWith( control = control.clone( true ) );

Example:



Code:
function resetFileControl() { var control = $("#fupexample"); control.replaceWith(control[0].outerHTML); }

Source Code:
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <script src="http://code.jquery.com/jquery-1.10.2.js"></script> <script language="javascript"> function resetFileControl() { var control = $("#fupexample"); control.replaceWith(control[0].outerHTML); } </script> </head> <body> <input type="file" id="fupexample" sytle="width:200px;" /> <input type="button" onclick="resetFileControl();" value="Reset" /> </body> </html>