ASM wrote:
RobG wrote:
ASM wrote:
Mick White wrote:
ASM wrote:
> function showform(mydiv) {
> var d = document.getElementById(mydiv).style;
> d.display = (d.display=='visible')? 'hidden' : 'visible';
> }
>
d.display=d.display=='none'?'':'none';
Mick
Oooppss ! :-(
but (as I think default is 'none')
d.display=d.display=='none'?'block':'none';
If you toggle between '' and 'none' (as suggested by Mick) it will
work for any element, block or otherwise.
Usually : yes
However, What I wanted to say was
the div(s) to show/hide is(are) 1st styled with { display: none }
so, I think the correct code would have to be :
d.display=d.display=='none'?'block':'none';
That infers that '' is incorrect, which it isn't. Setting the display
to '' means that it will return to the default or whatever it might
have been set to in a style rule.
Using none/'' has further benefits as: the OP is free to apply a
display attribute via CSS rule should that be required at some later
time without any modification to the script; and the script is
suitable for any element, not just those that have display:block by
default.
Some scripts toggle using none/block for table elements, which works
fine in some browsers but not in those where table elements are styled
with the appropriate CSS table display attribute values (table-cell,
table-row, etc.). On the other hand, none/'' will work fine for both.
In light of the above, I think none/'' is a better solution.
[...]
--
Rob