5
I have the following HTML:
<form action="cadastro/cadastrando.php" method="post">
<div class="elemf">
<label>Nome</label>
<input id="nome" type="text" name="nome" maxlength="15"/>
<p class="nome_erro">Campo Obrigatório. São permitidos letras e acentos.</p>
</div>
</form>
When I take the focus of the text field and it is empty, the message that is with the class should appear 'nome_erro'
. However it does not appear, it seems that the code executes the method below, but does not change the value of the attribute display
, continuing 'none'
.
Follows the CSS:
.erro {
font: 12px Verdana, Arial, Helvetica, sans-serif;
color: #ff0000;
left: 10px;
display: inline-block;
}
.nome_erro {
display: none;
}
And Javascript:
$(document).on('blur','input, textarea, select', function() {
if($(this).val() === '') {
switch($(this).attr('id')) {
case 'nome':
$('.nome_erro').addClass('erro');
break;
}
} else {
switch($(this).attr('id')) {
case 'nome':
$('#nome_erro').removeClass('erro');
break;
}
}
});
Still missing is the change @Leofelipe commented on in his reply. Switch selector to
#
for.
in Else .– Felipe Fonseca
Actually, the conflict was taking place, but the strange thing is that in other places of the project that I’m doing, I wasn’t with this problem, in a strange way
– leandroungari
that part of # and . was that I forgot to undo the changes before posting the question
– leandroungari
Remembering that the statement
!important
is discouraged as it can generate unwanted effects and "complex" style errors in projects with many lines / CSS files.– Kazzkiq