By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,814 Members | 2,162 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,814 IT Pros & Developers. It's quick & easy.

hide whole body but one div

P: n/a
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 ;)
Jul 2 '08 #1
Share this Question
Share on Google+
7 Replies


P: n/a
czechboy wrote:
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
Jul 2 '08 #2

P: n/a


czechboy wrote:
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.
Jul 2 '08 #3

P: n/a
Jorge wrote:
czechboy wrote:
>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
Jul 2 '08 #4

P: n/a
On Jul 2, 9:12*pm, Thomas 'PointedEars' Lahn <PointedE...@web.de>
wrote:
>
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.
Jul 2 '08 #5

P: n/a
Jorge wrote:
Thomas 'PointedEars' Lahn wrote:
>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
Jul 3 '08 #6

P: n/a
On Jul 2, 7:57*am, czechboy <oldrich.s...@gmail.comwrote:
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]
thanks ;)
Jul 3 '08 #7

P: n/a
SAM
dhtml a écrit :
On Jul 2, 7:57 am, czechboy <oldrich.s...@gmail.comwrote:
>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
Jul 3 '08 #8

This discussion thread is closed

Replies have been disabled for this discussion.