I'm having a hard time implementing the function of showing and hiding a div
in HTML with JavaScript.
What I need is that when a return of the servlet
is empty or null
, hide a certain div
.
The same should happen to the contrary, for example, when the return of servlet
is not empty or different from null
, div
appears.
Here's part of my code:
- This is the
div
I want to hide or show and theJavaScript
<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 of JavaScript and therefore would like your help.
Thanks in advance.