Reputation: 69
I want to clear my uploaded file with jquery. I tried this but not working.
var $el = $('#specialImg1');
$el.wrap('<form>').closest('form').get(0).reset();
$el.unwrap();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form>
<input id="specialImg1" type="file" name="specialImg" onchange="previewSpecialImage(1);" width="3000" height="2500" required="" class="user-error" aria-invalid="true">
</form>
Upvotes: 0
Views: 57
Reputation: 19986
Its already working. Try by loging it in console. Instead of the method you have written, you could simply use $('#specialImg1').val('');
<!DOCTYPE html>
<html>
<head>
<script>
function clearit() {
var $el = $('#specialImg1');
$el.wrap('<form>').closest('form').get(0).reset();
$el.unwrap();
console.log($("#specialImg1").val());
}
function upload(){
console.log($("#specialImg1").val());
}
</script>
</head>
<body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form>
<input id="specialImg1" type="file" name="specialImg" width="3000" height="2500" required="" class="user-error" aria-invalid="true" onchange="upload()">
</form>
<button onclick="clearit()">clearit</button>
</body>
</html>
Upvotes: 1