Connecting Tech Pros Worldwide Forums | Help | Site Map

Re: hide whole body but one div

Jorge
Guest
 
Posts: n/a
#1: Jul 2 '08
On Jul 2, 6:47*pm, Jorge <jo...@jorgechamorro.comwrote:
Quote:
No, because if the enclosing tag is hidden, all contained tags are
hidden as well.
>
I think you need to do something like this : :
>
var hiddenDiv, visibleDiv, e;
>
visibleDiv = document.getElementById('centerPage');
(hiddenDiv= document.createElement('div')).style.display= "none";
>
//Move all the body's elements to the hiddenDiv:
while (e= document.body.firstChild) {
* hiddenDiv.appendChild(e);
>
}
>
//Now the body is empty.
//Insert centerPage into the body
document.body.appendChild(visibleDiv);
//Insert the hiddenDiv into the body.
document.body.appendChild(hiddenDiv);
>
Forget that. There's no need to move things around :

document.body.style.visibility= "none";
(document.getElementById('centerPage')).style.visi bility= "visible";

--Jorge.

Evertjan.
Guest
 
Posts: n/a
#2: Jul 2 '08

re: Re: hide whole body but one div


czechboy wrote on 02 jul 2008 in comp.lang.javascript:
Quote:
Thanks for your answers... I will study links you provided me.
>
What I want to do is to load some page (like google.com) hide it and
then display only one div.
>
Problem with visibility is that hidden elements still keep their
places... for that display="none" looks much better, but unfortunately
does not work with nested elements to be visible
============= test.html =========
<body>
a
<div id=b>
b
</div>
c
</body>

<script type='text/javascript'>
document.body.innerHTML =
document.getElementById('b').innerHTML;
</script>
=================================

tested in IE7

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Dr J R Stockton
Guest
 
Posts: n/a
#3: Jul 3 '08

re: Re: hide whole body but one div


In comp.lang.javascript message <8282d067-ae06-4371-ae53-aeb17d248215@e5
3g2000hsa.googlegroups.com>, Wed, 2 Jul 2008 14:15:42, czechboy
<oldrich.svec@gmail.composted:
Quote:
>
>What I want to do is to load some page (like google.com) hide it and
>then display only one div.
If you really mean that, I see no good reason for loading the other
material.

If you want to have a number of divs, only one visible at a time but the
choice changing, then maybe, in pseudo-script :

<body>
<div ID=fred</div>
<div hidden>
<div ID=ATextA </div>
<div ID=BTextB </div>
<div ID=CTextC </div>
</div>
</body>

and use code to copy or move, each time, the div containing the required
text into and maybe out of div fred. Alternatively, the mobile material
could be literal JavaScript strings.

--
(c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.co.uk/- FAQish topics, acronyms, & links.
Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
Do not Mail News to me. Before a reply, quote with ">" or "" (SonOfRFC1036)
czechboy
Guest
 
Posts: n/a
#4: Jul 3 '08

re: Re: hide whole body but one div


Quote:
If you really mean that, I see no good reason for loading the other
material.
you are right. But then I can not guarantee complete functioning of
the code, because some of the necesary javascript might have been
erased.

I think I will use display="none" on separate divs ;)

thanks for your help
Closed Thread


Similar JavaScript / Ajax / DHTML bytes