Solved

scriptlet hide everything but div

Posted on 2010-09-12
7
336 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
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
The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Any business that wants to seriously grow needs to keep the needs and desires of an international audience of their websites in mind. Making a website friendly to international users isn’t prohibitively expensive and can provide an incredible return…
Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

839 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