¿Cómo va? Estoy tratando de restablecer la alerta/div cada vez que se valida el archivo para que solo muestre la alerta una vez. No puedo entender cómo eliminar el div/alerta cuando se presiona el mismo botón que ejecuta esta función.
function fileValidation() { var fileInput = document.getElementById('file'); var filePath = fileInput.value; // Allowing file type var allowedExtensions = /(\.jpg|\.jpeg|\.png|\.gif)$/i; if (!allowedExtensions.exec(filePath)) { $("#responsefromfileupload").replaceWith(`<div style="width: 50%;display:inline" class="alert alert-danger" role="alert"> This image file type is not accepted!</div>`); $("#responsefromfileupload").remove(); } if (allowedExtensions.exec(filePath)) { $("#responsefromfileupload").replaceWith(`<div style="width: 50%;display:inline" class="alert alert-success" role="alert"> This image is accepted!</div>`); } }