Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   JavaScript and Client-Side Browser Scripting (http://www.programmingforums.org/forum23.html)
-   -   .style.visibility = 'visible'; (http://www.programmingforums.org/showthread.php?t=14015)

paulchwd Sep 21st, 2007 4:45 PM

.style.visibility = 'visible';
 
Hello This will not work:

:

    function help()
    {
          var xx;
          xx = document.getElementById('xx');
          xx.style.visibility = 'visible';
      }


but this will

:

    function help()
    {
          var xx;
          xx = document.getElementById('xx');
          xx.style.visibility = 'hidden';
      }


The label (xx) is set to visible=false in visual studio..could this by why

Farflungfish Nov 8th, 2007 7:43 AM

Re: .style.visibility = 'visible';
 
:

  1. function toggle(DivId) {
  2.   if (document.getElementById(DivId).className == "visible") {
  3.     document.getElementById(DivId).className = "hidden";
  4.   } else {
  5.     document.getElementById(DivId).className = "visible";
  6.   }
  7. }


Created css styles with display.block: false / true; names visible/hidden.
works with everything not just divs

sorry if im completely off topic :)

cscgal Nov 8th, 2007 12:12 PM

Re: .style.visibility = 'visible';
 
There is no such thing as display:hidden. Your choices are display:block or display:none.

big_k105 Nov 8th, 2007 1:13 PM

Re: .style.visibility = 'visible';
 
@dani: He isn't using the display attribute, he is using the visibility attribute of style which does contain hidden and visible.

@paulchwd: I am not sure what is wrong, but from the looks of it, it is exactly what I did below and it works for me. http://www.kylekonline.com/test/visible.html <= if you want to see it working.
:

  1. <html>
  2. <head>
  3.         <title>Test Javascript</title>
  4.         <script type="text/javascript" language="javascript">
  5.         function showFirst()
  6.         {
  7.                 var xx;
  8.                 xx = document.getElementById('xx');
  9.                 xx.style.visibility = 'visible';
  10.         }
  11.  
  12.         function hideFirst()
  13.         {
  14.                 var xx;
  15.                 xx = document.getElementById('xx');
  16.                 xx.style.visibility = 'hidden';
  17.         }
  18.  
  19.         function showSecond()
  20.         {
  21.                 var yy;
  22.                 yy = document.getElementById('yy');
  23.                 yy.style.display = 'block';
  24.         }
  25.  
  26.         function hideSecond()
  27.         {
  28.                 var yy;
  29.                 yy = document.getElementById('yy');
  30.                 yy.style.display = 'none';
  31.         }
  32.         </script>
  33. </head>
  34. <body>
  35. <a href="javascript:;" onClick="showFirst()">Show First Div</a><br />
  36. <a href="javascript:;" onClick="hideFirst()">Hide First Div</a><br />
  37. <div id="xx">This is the first div called xx</div>
  38.  
  39. <br /><br />
  40.  
  41. <a href="javascript:;" onClick="showSecond()">Show Second Div</a><br />
  42. <a href="javascript:;" onClick="hideSecond()">Hide Second Div</a><br />
  43. <div id="yy">This is the second div called yy</div>
  44. </body>
  45. </html>


Farflungfish Nov 8th, 2007 4:28 PM

Re: .style.visibility = 'visible';
 
Quote:

Originally Posted by cscgal (Post 136486)
There is no such thing as display:hidden. Your choices are display:block or display:none.

sorry couldn't be bothered looking it up, i actually substituted block/none for true/false - the hidden/display is for the class names in the css.

though ill use hidden/visible for this css:
:

  1. .visible {
  2.         display: block;
  3. }
  4. .hidden {
  5.         display: none;
  6. }


:

  1. function toggle(DivId) {
  2.   if (document.getElementById(DivId).className == "visible") {
  3.     document.getElementById(DivId).className = "hidden";
  4.   } else {
  5.     document.getElementById(DivId).className = "visible";
  6.   }
  7. }


:

  1. <a href="#nothing" onclick="toggle('divid')"> Clicky clicky</a>
  2.  
  3. <div id='divid' class='hidden'>woot woot hide me show me</div>


Also using display:block/display:none means that IE won't substitute a hidden div with space, instead it will render nothing until told to.


All times are GMT -5. The time now is 4:43 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC