Delete photo when clicking on a link

0

Some time ago, I had a question here on the

asked by anonymous 26.12.2017 / 17:40

1 answer

1

It's quite simple just add the following line:

$("#excluir").click(function(){
    $("#fileUpload").val("");
    $("#imagem").css("display","none");
    $("#excluir").css("display","none");
});

So it will remove the value of the input file and hide the image again.

Complete code:

function readURL(input) {
    if (input.files && input.files[0]) {
        var reader = new FileReader();

        reader.onload = function (e) {
            $("#imagem").attr('src', e.target.result);           
        }     
        reader.readAsDataURL(input.files[0]);         
    }
}

$("#fileUpload").change(function(){
    readURL(this);
    $("#imagem").css("display","block");
    $("#excluir").css("display","block");
});

$("#excluir").click(function(){
    $("#fileUpload").val("");
    $("#imagem").css("display","none");
    $("#excluir").css("display","none");
});

Example: link

    
26.12.2017 / 17:57