1
Good night! I have a problem in the programming of an exercise, I need to remove these "spans" from the fields that are missing in the input, leaving only one that changes according to the need.
$(document).ready(function() {
$("#validar").click(function() {
$("input").each(function(index, element) {
if ($(element).val() == '') {
$("#validacao").append(element.id + "<br>");
}
});
});
});
div {
width: 40px;
height: 40px;
margin: 5px;
float: left;
border: 2px blue solid;
text-align: center;
}
span {
color: red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form>
<label for="nome">Nome</label>
<input type="text" id="nome">
<br>
<label for="cpf">CPF</label>
<input type="text" id="cpf">
<br>
<label for="rg">RG</label>
<input type="text" id="rg">
<br>
<input style="color: #0026ff" type="button" id="validar" value="Validar !" />
<br />
<span id="validacao">Campos Inválidos<br /></span>
</form>