[Javascript] Show and hide multiple div tags

Abyss - Information Info at Abyss.ws
Thu May 11 16:43:02 CDT 2006


Thank you steve you have filled in the missing pieces of the puzzle

I found out that the script worked with the style tag displayed but not when 
I used a class on the matter.

I tried programming the js for

if underfined then style = block but that did not work as undefined did not 
show up,

I tried your code (and it works....to which I truely appreciate)

but why and how does it work? would you just mind explaining it? because 
there is no use having the code and not understanding how it works

This is how I see the code

your giving the variable a value =    the code does a inline if of some sort
                                                     (not a style or style = 
none)

show.style.display                     = (!show.style.display || 
show.style.display=="none")


that is the part of the script i understand but what is this part of the 
script
? "block" : "none";

is that like an else? so if the first 2 criterier is met then it is block 
else none?

its the "?" and the ":" that have thrown me into confusion

thanks heap

Abyss.

----- Original Message ----- 
From: "Steve Clay" <sclay at ufl.edu>
To: "[JavaScript List]" <javascript at LaTech.edu>
Sent: Thursday, May 11, 2006 10:27 PM
Subject: Re[2]: [Javascript] Show and hide multiple div tags


> Wednesday, May 10, 2006, 5:13:13 AM, Abyss - Information wrote:
>>   if(show.style.display=="none")
>
> This is a common mistake.
> Until you've explicitly set the style property via JS or the style
> attribute in the markup, show.style.display will be undefined, not "none"
> or any other CSS value you might expect. That's why your current script
> takes 2 clicks: The display property first goes from (undefined) to "none"
> then finally "block". To suit your purposes, this would work:
>
> show.style.display =
>  ? "block" : "none";
>
>
> The general way to get a "computed" style requires you to use
> window.getComputedStyle or IE/win's currentStyle. Here's one such 
> function:
> http://www.somethingleet.com/forum/showthread.php?threadid=35610
>
> Steve
> -- 
> http://mrclay.org/
>
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript
> 





More information about the Javascript mailing list