View Full Version : show a div having style="display:none" when get value to the js variable

20 Jun 2012, 12:17 AM
Initially the div id =" showHide" is invisible. I want to make it visible when the value of vall is not null. But the code is not working. Though variable vall is getting values, the div is still not visible. What is the problem with js codescript?? How to solve this problem??


<script language="javascript">

var vall = "<%=vall%>";

<% System.out.println("jsvar="+vall);%>
/* vall is getting the values*/

if (vall != null)
mydiv = document.getElementById("showHide");
mydiv.style.visibility = "visible";


<div id =" showHide" style="display:none">



22 Jun 2012, 03:21 AM
The following works for me:

document.getElementById('showHide').setAttribute('style', 'display: block;');

Although there are compatibility issues with some versions of IE. I think in IE you can do:

document.getElementById('showHide').style.cssText = 'display: block;';