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
I believe that it’s not working,because variable “controlBn” is assigned only once (the first time equals $(‘#control’). And as that element is being replaced with a new clone of it, the var “controlBn” may be pointing to an inexistent element after that.
I would put just : $('#clear').on('click' ,function(){
$('#control').replaceWith( $('#control').val('').clone( true ) );
});
rather than the code above
(just a guess)
Click on Clear button for more than 1 time does n’t work.
Not working…
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
I believe that it’s not working,because variable “controlBn” is assigned only once (the first time equals $(‘#control’). And as that element is being replaced with a new clone of it, the var “controlBn” may be pointing to an inexistent element after that.
I would put just :
$('#clear').on('click' ,function(){
$('#control').replaceWith( $('#control').val('').clone( true ) );
});
rather than the code above
(just a guess)
Though .val(”) works for FF, but it does not work for IE.
.val(”) does not working in IE11. can we set .value = null; will that work for IE11?
Thank you. Just what I needed. Works perfectly ;)
@dibiler’s solution works great. The
control
variable has to be reinitialized inside theclick
callback function.A working demo is available here – http://jsfiddle.net/jesin/FEKrz/
Amazing!
Awesomeness!
Hey … it’s great! but not work to FILE type :-(
thank you, very helpful for me :)
I see people complaining about the clear button not working more than once…
How a about a much simpler solution, such as:
document.getElementById(“control”).value = “”;
Perfect!!!!
@Qiasar = you’re the killer :)
$(“#clear”).click(function(){
$(“#control”).val(”);
});
Its wrong ????
@Darbez
wait, are you saying
is wrong, or are you asking?
Because I’m asking. Is there anything wrong with doing it this way?
ie-8 support, enjoy =) my name is Maxmaxmaximus
Clear the form
Guys, this code works:
document.getElementById(“control”).value = “”;
This works for me
$(‘#control’).val(”);
Thank you! Works for me!
I tend to reset FileInput by resetting the
files
property to emptyFileList
.[inputTypeFile].files = new DataTransfer().files
where [inputTypeFile] = HTMLInputElement of Type File.