Jump to content

Very weird problem with style.display

- - - - -

  • Please log in to reply
2 replies to this topic

#1
DarkLordofthePenguins

DarkLordofthePenguins

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 409 posts
The following code collapses a div:

if( 1 == 1 ){

coldiv.style.display = "none";

}


The following code does something if the innerHTML is hide:

if( shspan.innerHTML == "hide" ){

alert( "hide" );

}


The following code is supposed to collapse the div when innerHTML is hide:

if( shspan.innerHTML == "hide" ){

coldiv.style.display = "none";

}


The first and second functions work. The third doesn't. Why this is happening is completely and utterly beyond me. Can anyone else figure this out?
Programming is a journey, not a destination.

#2
DarkLordofthePenguins

DarkLordofthePenguins

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 409 posts
Okay, I seem to have developed a workaround using a global variable rather than an HTML element in expanding and collapsing the div. I still can't discern the original problem, though.
Programming is a journey, not a destination.

#3
RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,254 posts
  • Location:C:\Countries\US
This seems to work for me:
<html> 

	<head> 

		<title> Test 01 </title> 

	</head> 

	<body> 

		<h1> Test 01 </h1> 

		<span id="some_span"> 

			normal 

		</span> 

		<BR> 

		<button onClick="show_div(false);"> 

			Hide 

		</button> 

		<button onClick="show_div(true);"> 

			Show 

		</button> 

		<BR> 

		<div id="some_div"> 

			some_stuff 

		</div> 

		<script type="text/javascript"> 

			function show_div(show_state){ 

				var a= document.getElementById("some_span"); 

				var b= document.getElementById("some_div"); 

				if (show_state == true) a.innerHTML= "normal"; 

				else a.innerHTML= "hide"; 

				do_work(a, b); 

			} 

			function do_work(shspan, coldiv){ 

				if (shspan.innerHTML == "hide"){ 

					coldiv.style.display= "none"; 

				} else { 

					coldiv.style.display= "inline"; 

				} 

			} 

		</script> 

	</body> 

</html> 





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users