I have a code where I can automatically view the photo after selecting it for upload. See:
<img class="img-fluid" style="width: 278px; height: 255px">
<div class="faq-profile-btn">
<label for="imagem" class="btn btn-primary waves-effect waves-light">Nova Foto</label>
<button type="button" class="btn btn-danger waves-effect waves-light" style="margin-top: -8px">Excluir Foto</button>
</div>
<input type="file" name="imagem" id="imagem" onchange="previewImagem()">
<script>
function previewImagem(){
var imagem = document.querySelector('input[name=imagem]').files[0];
var preview = document.querySelector('img');
var reader = new FileReader();
reader.onloadend = function () {
preview.src = reader.result;
}
if(imagem){
reader.readAsDataURL(imagem);
}else{
preview.src = "";
}
}
</script>
As a result:
The image appears correctly, but how do I, when I click delete, go back to the default photo?