Skip to content

Instantly share code, notes, and snippets.

@ihorduchenko
Last active October 6, 2017 08:58
Show Gist options
  • Save ihorduchenko/ebf9161562fbab9d76723480052aa51c to your computer and use it in GitHub Desktop.
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"]
(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