0
I’m having trouble implementing the function of showing and hiding a div
in HTML with Javascript.
What I need is that when a return from me servlet
is empty or null
, hide a certain div
.
The same should happen in reverse, for example, when the return of the servlet
is not empty or different from null
, to div
appears.
Follow part of my code:
- This is the
div
that I want to hide or show and the methodJavaScript
<script type="text/javascript">
var a = '<%=a.getSoldes()%>';
if (a !== null && a !== undefined) {
document.getElementById('descricaosolucao').style.display = "block";
} else {
document.getElementById('descricaosolucao').style.display = "none";
}
</script>
<div id="descricaosolucao" class="descricaosolucao" style="display: none;">
<p class="titulo-comp">Solução<%=dataSol%></p>
<p ><%=a.getSoldes()%></p>
</div>
I have little knowledge in Javascript and so I would like your help.
From now on, thank you.
That code
<%=a.getSoldes()%>
is that language? this is done on the server?– Sergio
I don’t think it’s Asp ?
– 13dev
What comes in console.log(a)?
– Diego Schmidt
From the syntax it looks like jsp, server side
– Isac
I am developing in Java WEB JSP and in code
<%=a.getSoldes()%>
should come a text. When it comes empty, the div should hide.– Rogério Eduard Schaefer
Why not do that
if
directly in JSP since it is not something that can change after the page is loaded ? You can do theif
and apply a class css withdisplay:none
directly in the attributeclass
– Isac
Hello Isac. I’m a layman yet. Please, could you show me what it’s like in practice? How do I make the div receive the JSP parameter?
– Rogério Eduard Schaefer