Re: Possible to have nested

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Quoted text here. Click to load it

Your code looks fine to me and works as you intend in IE6 and Opera 7.11,
however browsers with the Gecko engine (Mozilla, Netscape) show the
behaviour you describe.  I think this behaviour is wrong, but I am sure
more experienced members of the group will soon put me right. :)


Re: Possible to have nested

Quoted text here. Click to load it

Of course. Wasn't this easy to check from HTML specifications?

Quoted text here. Click to load it

Why bother playing with it then? You can throw all kinds of tag soups
and sallads at browsers and watch them misbehave, but it's not
civilized entertainment.

Quoted text here. Click to load it

Well, then it's not an HTML problem and surely has nothing to do with
the question on the Subject line.

Quoted text here. Click to load it

All correctly behaving browsers ignore that style sheet. Well,
technically they don't ignore the last declaration, but it coincides
with the initial (default) setting. This, in turn, has nothing to do
with HTML and nothing to do with JavaScript.

Hint: Create an HTML page that works robustly. Use validators to
help you in this if you understand what a DTD is. Time permitting, add
then some optional CSS. Don't forget to use available CSS checkers.
Having done this, you might try to play with JavaScript, and then
comp.lang.javascript is surely the best group to ask for help.

Yucca, /
Pages about Web authoring:

Re: Possible to have nested

Ok here is a validated document then. Still the same problem. Maybe you are
right this is a javascript problem but it does not have to be. I would say
that it could also be an html problem for example if nested <div> tags is
not feasible (now you say it is feasible so I guess you are right that it is
not a html problem but I was too stupid to realise this) or it can be a
rendering problem in the browser (IE and Opera does not behave in the same
way as for example Netscape in this case). Well I will give it a try in
javascript newsgroup but I guess they will forward me to yet another

Anyway thanx for you help
/Hans Börjesson

 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

<div id="div1" >
This is Div1!
<div id="div2" >
  This is Div2!

<form id="frm1" action=" /" method="post">
<input type="button" value="Toggle Div1" onclick="ToggleDiv('div1');">
<input type="button" value="Toggle Div2" onclick="ToggleDiv('div2');">

<script language="javascript" type="text/javascript">
function ToggleDiv(div_in) {
  var mydiv;
  mydiv = document.getElementById(div_in);
  if ( == "hidden") = "visible";
  else = "hidden";

Re: Possible to have nested

Hans Börjesson wrote:
Quoted text here. Click to load it

I get the same problem as you do, in both Mozilla and IE.  I would certainly
say that it is a JS problem, but I can't help you there, I'm afraid.

Good luck with it.


Mark Parnell

Re: Possible to have nested

Hi Mark!

I see when I removed the <table> I had in inside my "outer" div also IE
behaves the same way as NN6+ (if you test the html in my original post you
will see that IE will behave in another way). I removed my <table> when I
created the validated sorce code to make the code as small as possible but I
only tested the result in NN6+ and the problem still occured but the problem
was now also the same in IE.

Thanks for letting me know.

/Hans Börjesson

Quoted text here. Click to load it

Re: Possible to have nested

Quoted text here. Click to load it

<snip code>

If you have a quick look at section 11.2 of the CSS2 specs:
you will see that the default value for the visibility property is inherit.
That is, inherit the visibility property value of the parent element.

When you first open this page div1 _inherits_ visible from the body element
(which BTW has inherited this from the html element). div 2 also _inherits_

When you click toggle div 1 the visibility property of div1 gets set to
hidden. Since the visibility property of div2 is still inherit then div2
disappears as well, since it inherits hiddenness.

When you click toggle div 1 again, the reverse happens, with the exception
that the value for div1 is now visible. Div2 inherits this and magically

Now, click toggle div2. Sure enough div2 disappears. Click toggle div2
again. Now, the visibility property has a value of visible, not inherit.
Div2 reappears.

Now, click toggle div1. Div1 is now hidden, it disappears. What about div2
though. It no longer inherits this value, its visibility property has the
value visible, just like you told it to. Div2 remains visible.

That wasn't too hard after all now, was it. :-)

Although the spec is somewhat unclear on this I think is quite in order to
have visible elements nested inside invisible elements. The spec actually
does say the visiblity property specifies whether the boxes *generated by an
element* are rendered. It does not say anything about boxes generated by
child elements, I think they should behave independently.

IMHO the browsers where this 'problem' of yours does not appear are, in
fact, the ones that are broken.

I doubt that you will get any joy over at clj as this is a CSS issue, not a
javascript one. That is why I answered here rather than over there.

If you want these divs to behave the way I think you do then change = "visible";
to = "inherit";


Re: Possible to have nested

Ahh I see! Thanks for a good explanation Richard.

I found out that IE behaved the same way with my validated code (actually I
removed a <table> inside my "outer" <div> that seems to make IE behave
differently. If I "re-add" this table (which you can see in my original
post) in the validated source code IE behaves differently than NN6+.

Once again thanks for pointing me in the right direction.

/Hans Börjesson

Re: Possible to have nested

Quoted text here. Click to load it

I suspect because IE has more bugs than a rain forest.

Tables are layed out differently than other elements. I suspect that IE is
saying "I can't be bothered, lets just disappear the whole table, contents
and all".

If two browsers behave differently and one of them is IE then it's a safe
bet the other browser is doing it correctly (unless of course if it's
Netscape 4.x).

On reflection: since the specs are possibly open to interpretation you
should anticipate those interpretations. In this case, pressing "toggle div
1" should disappear both divs, just to be sure (and I assume that is what
you want).

Quoted text here. Click to load it

No problem.


Site Timeline