Solved

scriptlet hide everything but div

Posted on 2010-09-12
7
343 Views
Last Modified: 2012-05-10
I want to have a bookmark so when I click on it, everything hides except what is in the div with the id pageContainer.  This is for a news site.  Basically I want to hide the surrounding area except the main body area.
0
Comment
Question by:jackjohnson44
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 5

Expert Comment

by:roxviper
ID: 33660187
0
 
LVL 14

Accepted Solution

by:
sam2912 earned 500 total points
ID: 33660614
Working example:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<style type="text/css">
* {
   font-size: 18px;
   font-family: Calibri, Arial, Verdana;
}
#pageContainer {
   border: 1px solid red;
   padding: 10px;
}
</style>
<script type="text/javascript">
//<![CDATA[
function showDiv(divId) {
	var all = document.getElementsByTagName("*");
	for(i=0;i<all.length;i++) {
			all[i].style.display = "none";
	}
	var elem = document.getElementById(divId);
	do { elem.style.display = "block"; } while(elem = elem.parentNode);
}
//]]>
</script>
</head>

<body>
<h1>Heading</h1>
<p>Some Text</p>
<p>Some Text</p>
<div id="pageContainer">Text in div pageContainer</div>
<p><a href="#" onclick="showDiv('pageContainer');">This bookmark hides display of everything other than pageContainer</a></p>
<p>Some Text</p>
<p>Some Text</p>
</body>
</html>

Open in new window

0
 
LVL 22

Expert Comment

by:kadaba
ID: 33663397
<a href="#" onclick="showDiv('pageContainer');">
should be
<a href="#" onclick="showDiv('pageContainer');return false;">

and also please check for any script errors.
0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
LVL 14

Expert Comment

by:sam2912
ID: 33664625
There's nothing wrong with that, but since you insist, here's the updated code.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<style type="text/css">
* {
   font-size: 18px;
   font-family: Calibri, Arial, Verdana;
}
#pageContainer {
   border: 1px solid red;
   padding: 10px;
}
</style>
<script type="text/javascript">
//<![CDATA[
function showDiv(divId) {
        var all = document.getElementsByTagName("*");
        for(i=0;i<all.length;i++) {
                        all[i].style.display = "none";
        }
        var elem = document.getElementById(divId);
        do { elem.style.display = "block"; } while(elem = elem.parentNode);
}
//]]>
</script>
</head>

<body>
<h1>Heading</h1>
<p>Some Text</p>
<p>Some Text</p>
<div id="pageContainer">Text in div pageContainer</div>
<p><a href="#" onclick="showDiv('pageContainer'); return false;">This bookmark hides display of everything other than pageContainer</a></p>
<p>Some Text</p>
<p>Some Text</p>
</body>
</html>

Open in new window

0
 
LVL 22

Expert Comment

by:kadaba
ID: 33664671
sam,
No offense.
I always use return false for it not to evaluate to href which is the default behavior.
Your script still has errors, at least I got it in IE 8 and FF.
So pointed them out.

No points for me, glad to help a lending hand.

Best,
kadaba
0
 

Author Closing Comment

by:jackjohnson44
ID: 33772604
cc
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
This article was originally published on Monitis Blog, you can check it here . Today it’s fairly well known that high-performing websites and applications bring in more visitors, higher SEO, and ultimately more sales. By the same token, downtime…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question