?
Solved

scriptlet hide everything but div

Posted on 2010-09-12
7
Medium Priority
?
346 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 2000 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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
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

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Suggested Courses

777 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