<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Team Tutorials &#187; javasciprt</title>
	<atom:link href="http://teamtutorials.com/tag/javasciprt/feed" rel="self" type="application/rss+xml" />
	<link>http://teamtutorials.com</link>
	<description></description>
	<lastBuildDate>Tue, 27 Dec 2011 18:58:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Hide and Show a Div Using Javascript</title>
		<link>http://teamtutorials.com/web-development-tutorials/hide-and-show-a-div-using-javascript?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=hide-and-show-a-div-using-javascript</link>
		<comments>http://teamtutorials.com/web-development-tutorials/hide-and-show-a-div-using-javascript#comments</comments>
		<pubDate>Sun, 27 Jul 2008 15:01:47 +0000</pubDate>
		<dc:creator>John Ward</dc:creator>
				<category><![CDATA[HTML Tutorials]]></category>
		<category><![CDATA[JavaScriptTutorials]]></category>
		<category><![CDATA[Web Development Tutorials]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[javasciprt]]></category>
		<category><![CDATA[web design]]></category>
		<category><![CDATA[xhtml]]></category>

		<guid isPermaLink="false">http://teamtutorials.com/?p=1612</guid>
		<description><![CDATA[This tutorial will show you how to create a hidden Div and display it with the click of a link. There are a few reasons you may want to hide a Div in a website design. You may want to create a drop down type menu or a box that will show more information when you click a link. Another reason would be for SEO purposes. In theory hiding information in a Div is not against Google’s rules. As long as the user can still see the content when clicking a button you are not displaying different information to the user than you are to the search engine.]]></description>
			<content:encoded><![CDATA[<p>This tutorial will show you how to create a hidden Div and display it with the click of a link. There are a few reasons you may want to hide a Div in a website design. You may want to create a drop down type menu or a box that will show more information when you click a link. Another reason would be for SEO purposes. In theory hiding information in a Div is not against Google’s rules. As long as the user can still see the content when clicking a button you are not displaying different information to the user than you are to the search engine.</p>
<p>First we are going to start with a very basic page layout and create a 2 Divs. One will be shown and one will be hidden. Here is the starting code.</p>
<pre class="brush: xml; title: Code Snippet:; notranslate">
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
&lt;title&gt;Hidden Div&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;div id=&quot;main&quot;&gt;This is not hidden.&lt;/div&gt;

&lt;div id=&quot;hidden&quot;&gt;This is hidden.&lt;/div&gt;

&lt;/body&gt;
&lt;/html&gt;

Ok now I will add some basic style to these boxes.
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
&lt;title&gt;Hidden Div&lt;/title&gt;

&lt;style type=&quot;text/css&quot;&gt;
&lt;!--
#main{
	width:500px;
	height: 20px;
	background: lightblue;
}
#hidden {
	width:300px;
	height:20px;
	background: lightgrey;
}
--&gt;
&lt;/style&gt;

&lt;/head&gt;

&lt;body&gt;
&lt;div id=&quot;main&quot;&gt;This is not hidden.&lt;/div&gt;

&lt;div id=&quot;hidden&quot;&gt;This is hidden.&lt;/div&gt;

&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>The page should look like this so far.<br />
<a href="http://teamtutorials.com/wp-content/uploads/2008/07/hide-show-div-with-javascript-01.jpg"><img src="http://teamtutorials.com/wp-content/uploads/2008/07/hide-show-div-with-javascript-01.jpg" alt="" title="hide-show-div-with-javascript-01" width="510" height="80" class="alignnone size-medium wp-image-1613" /></a></p>
<p>Now to hide the div. To do this we will change the display to none in the CSS for the #hidden div. See the code below.</p>
<pre class="brush: xml; title: Code Snippet:; notranslate">
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
&lt;title&gt;Hidden Div&lt;/title&gt;

&lt;style type=&quot;text/css&quot;&gt;
&lt;!--
#main{
	width:500px;
	height: 20px;
	background: lightblue;
}
#hidden {
	width:300px;
	height:20px;
	background: lightgrey;
	display: none;
}
--&gt;
&lt;/style&gt;

&lt;/head&gt;

&lt;body&gt;
&lt;div id=&quot;main&quot;&gt;This is not hidden.&lt;/div&gt;

&lt;div id=&quot;hidden&quot;&gt;This is hidden.&lt;/div&gt;

&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>Now when you preview the page you will not see the Div.<br />
<a href="http://teamtutorials.com/wp-content/uploads/2008/07/hide-show-div-with-javascript-02.jpg"><img src="http://teamtutorials.com/wp-content/uploads/2008/07/hide-show-div-with-javascript-02.jpg" alt="" title="hide-show-div-with-javascript-02" width="500" height="51" class="alignnone size-full wp-image-1614" /></a></p>
<p>In order to show the div we will need to add a Javascript function. We will pass the ID attribute of the Div to the function. Basically this means that we can use this one function to show or hide more than one Div on the same page. Below is the Javascript code that we will add the the Head section of the page.</p>
<pre class="brush: jscript; title: Code Snippet:; notranslate">
&lt;script language=&quot;JavaScript&quot;&gt;
	function toggle(id) {
		var state = document.getElementById(id).style.display;
			if (state == 'block') {
				document.getElementById(id).style.display = 'none';
			} else {
				document.getElementById(id).style.display = 'block';
			}
		}
&lt;/script&gt;
</pre>
<p>The script above is creating the function “toggle” an passing the value “id”. Next we are using the Document Object Model to get the current state of the display attribute. Then if “display: block;” for the #hidden div we will change it to be “display: none;” else we will change the display to none. </p>
<p>Add the code to your page in the head just below the style.</p>
<pre class="brush: xml; title: Code Snippet:; notranslate">
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
&lt;title&gt;Hidden Div&lt;/title&gt;

&lt;style type=&quot;text/css&quot;&gt;
&lt;!--
#main{
	width:500px;
	height: 20px;
	background: lightblue;
}
#hidden {
	width:300px;
	height:20px;
	background: lightgrey;
	display: none;
}
--&gt;
&lt;/style&gt;

&lt;script language=&quot;JavaScript&quot;&gt;
	function toggle(id) {
		var state = document.getElementById(id).style.display;
			if (state == 'block') {
				document.getElementById(id).style.display = 'none';
			} else {
				document.getElementById(id).style.display = 'block';
			}
		}
&lt;/script&gt; 

&lt;/head&gt;

&lt;body&gt;
&lt;div id=&quot;main&quot;&gt;This is not hidden.&lt;/div&gt;

&lt;div id=&quot;hidden&quot;&gt;This is hidden.&lt;/div&gt;

&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>Now all we have to do is create a link that will call the toggle function and pass the ID of the Div we want to toggle. We will create a link that goes no where and add the onclick property below.</p>
<pre class="brush: xml; title: Code Snippet:; notranslate">
&lt;a href=&quot;#&quot; onclick=&quot;toggle('hidden');&quot;&gt;Toggle Div&lt;/a&gt;
</pre>
<p>Add the link to your visible div.</p>
<pre class="brush: xml; title: Code Snippet:; notranslate">
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
&lt;title&gt;Hidden Div&lt;/title&gt;

&lt;style type=&quot;text/css&quot;&gt;
&lt;!--
#main{
	width:500px;
	height: 20px;
	background: lightblue;
}
#hidden {
	width:300px;
	height:20px;
	background: lightgrey;
	display: none;
}
--&gt;
&lt;/style&gt;

&lt;script language=&quot;JavaScript&quot;&gt;
	function toggle(id) {
		var state = document.getElementById(id).style.display;
			if (state == 'block') {
				document.getElementById(id).style.display = 'none';
			} else {
				document.getElementById(id).style.display = 'block';
			}
		}
&lt;/script&gt;

&lt;/head&gt;

&lt;body&gt;
&lt;div id=&quot;main&quot;&gt;
	This is not hidden.
	&lt;a href=&quot;#&quot; onclick=&quot;toggle('hidden');&quot;&gt;Toggle Div&lt;/a&gt;
&lt;/div&gt;

&lt;div id=&quot;hidden&quot;&gt;This is hidden.&lt;/div&gt;

&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>Save the file and test. You should not see the Div when the page loads. When you click the toggle link the hidden box will appear.<br />
<a href="http://teamtutorials.com/wp-content/uploads/2008/07/hide-show-div-with-javascript-03.jpg"><img src="http://teamtutorials.com/wp-content/uploads/2008/07/hide-show-div-with-javascript-03.jpg" alt="" title="hide-show-div-with-javascript-03" width="500" height="175" class="alignnone size-full wp-image-1615" /></a></p>
<p>Here is an example of something you could use this for. I have a site for deals on clothing. Now if we wanted to add some quality SEO content to help the site rank we could put it in a hidden div so that it doesn’t distract the customer.<br />
<a href="http://teamtutorials.com/wp-content/uploads/2008/07/hide-show-div-with-javascript-04.jpg"><img src="http://teamtutorials.com/wp-content/uploads/2008/07/hide-show-div-with-javascript-04.jpg" alt="" title="hide-show-div-with-javascript-04" width="500" height="277" class="alignnone size-full wp-image-1616" /></a></p>
<p>When the div is clicked it could expand with SEO rich content and links.<br />
<a href="http://teamtutorials.com/wp-content/uploads/2008/07/hide-show-div-with-javascript-05.jpg"><img src="http://teamtutorials.com/wp-content/uploads/2008/07/hide-show-div-with-javascript-05.jpg" alt="" title="hide-show-div-with-javascript-05" width="500" height="264" class="alignnone size-full wp-image-1617" /></a></p>
<p>I know the tutorial was pretty basic, but I hope that the example above gives you an idea of how this can be used. I may also expand this into another tutorial and show you how to create a nice menu using the technique.</p>
<h2  class="related_post_title">Related Posts</h2><ul class="related_post"><li><a href="http://teamtutorials.com/web-development-tutorials/using-jquery-to-reorder-a-list-and-update-a-database" title="Using jQuery to Reorder a List and Update a Database">Using jQuery to Reorder a List and Update a Database</a></li><li><a href="http://teamtutorials.com/web-development-tutorials/html-tutorials/javascript-progress-bar" title="JavaScript Progress Bar">JavaScript Progress Bar</a></li><li><a href="http://teamtutorials.com/other-tutorials/receiving-dynamic-textbox-data" title="Receiving Dynamic Textbox Data">Receiving Dynamic Textbox Data</a></li><li><a href="http://teamtutorials.com/web-development-tutorials/dynamically-add-textbox-to-site" title="Dynamically Add Textbox to Site">Dynamically Add Textbox to Site</a></li><li><a href="http://teamtutorials.com/web-development-tutorials/styling-html-tables-with-tablecloth" title="Styling HTML Tables with TableCloth">Styling HTML Tables with TableCloth</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://teamtutorials.com/web-development-tutorials/hide-and-show-a-div-using-javascript/feed</wfw:commentRss>
		<slash:comments>27</slash:comments>
		</item>
	</channel>
</rss>

