How do I do it?
Note: I have seen an example using thymeleaf but it does not work, that is, the namespace does not recognize the project.
Someone there to help?
As some have said, make the div initially invisible. You can even leave the message already set in it:
CSS:
.divSucesso{
display:none;
}
HTML:
<div id="divSucesso" class="divSucesso">Usuário salvo com sucesso</div>
When the user is saved, make this div appear, using JQuery:
$("#divSucesso").show();
If you need to hide the div again, use:
$("#divSucesso").hide();
If you need to change the displayed message, you can use JQuery again:
$("#divSucesso").html("Nova mensagem");
If I understand your question, you can only use css to solve this question. You can define specific rules for an element when it is empty through the pseudo-class :empty
:
div {
border : 2px solid #1abc9c;
color : #333;
padding: 4px;
}
div:empty {
display: none
}
<div><!-- DIV VAZIA --></div>
<div>Tenho conteúdo</div>
Half a question, but according to your description of the problem:
CSS:
.hide{
display:none;
}
Html:
<div class="_div"> </div>
JavaScript:
...
if ($("._div").html()==""){
$("._div").addClass("hide");
}
Although normal behavior of a DIV
is invisible when no content.