I don’t need to be able to add multiple files to a page, and the code generally works. But the block that is dynamically created, it no longer works.
$('.block-file input[type="file"]').change(function(){ $(this).prev().addClass("del"); $(this).prev().removeClass("add"); $(this).prev().find("span").text($(this).val()); $(this).prev().attr('onclick', '$(this).parent().remove();') $(this).parent().parent().append('<div class="block-file"><a class="add" onclick="$(this).next().click();"><i class="fa fa-plus-circle"></i><span>Вы можете добавить фото</span></a><input type="file" style="visibility:hidden;width: 0;"></div>'); }); HTML
<div class="block-file"> <a class="add" onclick="$(this).next().click();"><i class="fa fa-plus-circle"></i><span>Вы можете добавить фото</span></a> <input type="file" style="visibility:hidden;width: 0;"> </div>