Last active
October 6, 2017 08:58
-
-
Save ihorduchenko/ebf9161562fbab9d76723480052aa51c to your computer and use it in GitHub Desktop.
Playing with $(this) and .each (jQuery) | Contact Form 7: Delete file from input[type="file"]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function ($) { | |
$('.wpcf7-file').each(function() { | |
$(this).change(function() { | |
var file = $(this)[0].files[0]; | |
console.log(file); | |
if (file) { | |
console.log("Not empty"); | |
$(this).parents("p").siblings(".delete-file").show(); | |
$(this).parents("p").siblings(".file-name").show().html(file.name); | |
} | |
}); | |
}); | |
$(".delete-file").each(function() { | |
$(this).click(function () { | |
console.log("deleted"); | |
$(this).prev().hide().html(''); | |
$(this).next().children(".wpcf7-file").replaceWith($(".wpcf7-file").val('').clone(true)); | |
$(this).hide(); | |
}); | |
}); | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment