Connecting Tech Pros Worldwide Forums | Help | Site Map

hide whole body but one div

czechboy
Guest
 
Posts: n/a
#1: Jul 2 '08
Hi,
I can use document.body.style.display="none" to hide whole page but
then if I want to display one div only by
document.getElementById("centerPage").style.displa y="" it does not
work...

so is there any easy and fast way how to completely hide whole body
and to keep displayed one nested div only?

thanks ;)

Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a
#2: Jul 2 '08

re: hide whole body but one div


czechboy wrote:
Quote:
I can use document.body.style.display="none" to hide whole page but
then if I want to display one div only by
document.getElementById("centerPage").style.displa y="" it does not
work...
>
so is there any easy and fast way how to completely hide whole body
and to keep displayed one nested div only?
<http://groups.google.com/group/comp.lang.javascript/msg/29481241b1d86da3>
<http://www.jibbering.com/faq/#FAQ2_3>


PointedEars
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee
Jorge
Guest
 
Posts: n/a
#3: Jul 2 '08

re: hide whole body but one div




czechboy wrote:
Quote:
Hi,
I can use document.body.style.display="none" to hide whole page but
then if I want to display one div only by
document.getElementById("centerPage").style.displa y="" it does not
work...
>
so is there any easy and fast way how to completely hide whole body
and to keep displayed one nested div only?
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);

--Jorge.
Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a
#4: Jul 2 '08

re: hide whole body but one div


Jorge wrote:
Quote:
czechboy wrote:
Quote:
>I can use document.body.style.display="none" to hide whole page but
>then if I want to display one div only by
>document.getElementById("centerPage").style.displ ay="" it does not
>work...
>>
>so is there any easy and fast way how to completely hide whole body
>and to keep displayed one nested div only?
>
No, because if the enclosing tag is hidden, all contained tags are
hidden as well.
Obviously you don't know the `visibility' CSS property.


PointedEars
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee
Jorge
Guest
 
Posts: n/a
#5: Jul 2 '08

re: hide whole body but one div


On Jul 2, 9:12*pm, Thomas 'PointedEars' Lahn <PointedE...@web.de>
wrote:
Quote:
>
Obviously you don't know the `visibility' CSS property.
>
Yes I do know style.visibility.
But I don't know how to "undo" a body.style.DISPLAY= "none" on an
inner element.

These are two different things, isn't it ?

Thanks,
--Jorge.
Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a
#6: Jul 3 '08

re: hide whole body but one div


Jorge wrote:
Quote:
Thomas 'PointedEars' Lahn wrote:
Quote:
>Obviously you don't know the `visibility' CSS property.
>
Yes I do know style.visibility.
But I don't know how to "undo" a body.style.DISPLAY= "none" on an
inner element.
>
These are two different things, isn't it ?
They are, but either you misread the OP's question or you missed the point
of my posting.


PointedEars
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee
dhtml
Guest
 
Posts: n/a
#7: Jul 3 '08

re: hide whole body but one div


On Jul 2, 7:57*am, czechboy <oldrich.s...@gmail.comwrote:
Quote:
Hi,
I can use document.body.style.display="none" to hide whole page but
then if I want to display one div only by
document.getElementById("centerPage").style.displa y="" it does not
work...
>
document.getElementById("centerPage").style.displa y=""

Changes the style attribute. So whatever was in the cascade above (e.g
a stylesheet), will be applied to the element. If the most specific
cascading stylesheet rule for that element had display: none, then
setting display="" the browser will apply that cascaded rule to that
element.

It is also entirely possible that the element's ancestor has display:
none, so in that case, setting the display of the element itself will
change it's style attribute but it won't generate any box for that
element (which is not rendered because its ancestor is not).

display can be, but is not by default, inherited. If the element has
display: inherit, it will take on the value of the element's parent's
display (inherit doesn't work in IE). However, if the element has an
ancestor with display: none, then it is not rendered (regardless of
whatever display it may have inherited from its parent). It will still
generate no box, no matter what.

[snip]
Quote:
thanks ;)
SAM
Guest
 
Posts: n/a
#8: Jul 3 '08

re: hide whole body but one div


dhtml a écrit :
Quote:
On Jul 2, 7:57 am, czechboy <oldrich.s...@gmail.comwrote:
Quote:
>Hi,
>I can use document.body.style.display="none" to hide whole page but
>then if I want to display one div only by
>document.getElementById("centerPage").style.displ ay="" it does not
>work...
>>
document.getElementById("centerPage").style.displa y=""
The answer has been given

in address bar type :

javascript:document.body.innerHTML=document.getEle mentById('centerPage').innerHTML;

To get back the page : button back ;-)

--
sm
Closed Thread


Similar JavaScript / Ajax / DHTML bytes