<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: How to hide, show, or toggle your div</title>
	<atom:link href="http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/</link>
	<description>Random Snippets of Code for Web Developers</description>
	<lastBuildDate>Thu, 19 Jan 2012 11:30:51 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
	<item>
		<title>By: Jaggs</title>
		<link>http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/comment-page-4/#comment-65893</link>
		<dc:creator>Jaggs</dc:creator>
		<pubDate>Mon, 19 Dec 2011 09:45:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/#comment-65893</guid>
		<description>HTML Code :

&lt;a&gt;




JavaScript :
function toggle5(showHideDiv, switchImgTag) {
       var ele = document.getElementById(showHideDiv);
       var imageEle = document.getElementById(switchImgTag);
if(ele.style.display == “block”) {
ele.style.display = “none”;
     imageEle.innerHTML = “” +       ctrl.getAttribute(“entity”);
}
else {
ele.style.display = “block”;
imageEle.innerHTML = “” + ctrl.getAttribute(“entity”);
}
}</description>
		<content:encoded><![CDATA[<p>HTML Code :</p>
<p><a></p>
<p>JavaScript :<br />
function toggle5(showHideDiv, switchImgTag) {<br />
       var ele = document.getElementById(showHideDiv);<br />
       var imageEle = document.getElementById(switchImgTag);<br />
if(ele.style.display == “block”) {<br />
ele.style.display = “none”;<br />
     imageEle.innerHTML = “” +       ctrl.getAttribute(“entity”);<br />
}<br />
else {<br />
ele.style.display = “block”;<br />
imageEle.innerHTML = “” + ctrl.getAttribute(“entity”);<br />
}<br />
}</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jaggs</title>
		<link>http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/comment-page-4/#comment-65825</link>
		<dc:creator>Jaggs</dc:creator>
		<pubDate>Mon, 19 Dec 2011 06:09:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/#comment-65825</guid>
		<description>Hi Allen,

Thanks a lot for the javascript examples above.It helped me a lot.But one question i have been trying the same example using the Plus and minus images in different browsers.But the image doesn&#039;t seem to be toggling.i have placed the code below  

HTML Code :
&lt;div id=&quot;&quot;&gt;
    &lt;a id=&quot;imageDivLink&quot; entity=&quot;&quot; href=&quot;javascript:toggle5(&#039;&#039;, &#039;imageDivLink&#039;);&quot;&gt;&lt;img src=&#039;/images/plus.gif&#039;/&gt;&lt;/a&gt;
    


JavaScript :
function toggle5(showHideDiv, switchImgTag) {
        var ele = document.getElementById(showHideDiv);
        var imageEle = document.getElementById(switchImgTag);
        if(ele.style.display == &quot;block&quot;) {
                ele.style.display = &quot;none&quot;;
		imageEle.innerHTML = &quot;&lt;img src=&#039;/images/plus.gif&#039;&gt;&quot; + ctrl.getAttribute(&quot;entity&quot;);
		
        }
        else {
                ele.style.display = &quot;block&quot;;
                imageEle.innerHTML = &quot;&lt;img src=&#039;/images/minus.gif&#039;&gt;&quot; + ctrl.getAttribute(&quot;entity&quot;);
                
        }
}</description>
		<content:encoded><![CDATA[<p>Hi Allen,</p>
<p>Thanks a lot for the javascript examples above.It helped me a lot.But one question i have been trying the same example using the Plus and minus images in different browsers.But the image doesn&#8217;t seem to be toggling.i have placed the code below  </p>
<p>HTML Code :<br />
&lt;div id=&quot;&#8221;&gt;<br />
    &lt;a id=&quot;imageDivLink&quot; entity=&quot;&#8221; href=&#8221;javascript:toggle5(&#8221;, &#8216;imageDivLink&#8217;);&#8221;&gt;&lt;img src=&#039;/images/plus.gif&#8217;/&gt;</p>
<p>JavaScript :<br />
function toggle5(showHideDiv, switchImgTag) {<br />
        var ele = document.getElementById(showHideDiv);<br />
        var imageEle = document.getElementById(switchImgTag);<br />
        if(ele.style.display == &#8220;block&#8221;) {<br />
                ele.style.display = &#8220;none&#8221;;<br />
		imageEle.innerHTML = &#8220;&lt;img src=&#039;/images/plus.gif&#8217;&gt;&#8221; + ctrl.getAttribute(&#8220;entity&#8221;);</p>
<p>        }<br />
        else {<br />
                ele.style.display = &#8220;block&#8221;;<br />
                imageEle.innerHTML = &#8220;&lt;img src=&#039;/images/minus.gif&#8217;&gt;&#8221; + ctrl.getAttribute(&#8220;entity&#8221;);</p>
<p>        }<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bo</title>
		<link>http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/comment-page-4/#comment-65593</link>
		<dc:creator>Bo</dc:creator>
		<pubDate>Sun, 18 Dec 2011 18:10:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/#comment-65593</guid>
		<description>Hello Allen I am having trouble getting multiple of your tutorial working.. when I have 2 or more triggers, and I click on any of them the 1st one triggers.  The only thing is that I am going to be having a dynamic site and I want it to just know that I am clicking on a specific button and have that one show.  If you could help me I would appreciate it so much!</description>
		<content:encoded><![CDATA[<p>Hello Allen I am having trouble getting multiple of your tutorial working.. when I have 2 or more triggers, and I click on any of them the 1st one triggers.  The only thing is that I am going to be having a dynamic site and I want it to just know that I am clicking on a specific button and have that one show.  If you could help me I would appreciate it so much!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: MrThomas</title>
		<link>http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/comment-page-4/#comment-65292</link>
		<dc:creator>MrThomas</dc:creator>
		<pubDate>Sun, 18 Dec 2011 00:00:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/#comment-65292</guid>
		<description>Btw, i was talking about the last example on this page, so it would be the .getElementByTagName()</description>
		<content:encoded><![CDATA[<p>Btw, i was talking about the last example on this page, so it would be the .getElementByTagName()</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: MrThomas</title>
		<link>http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/comment-page-4/#comment-65291</link>
		<dc:creator>MrThomas</dc:creator>
		<pubDate>Sat, 17 Dec 2011 23:57:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/#comment-65291</guid>
		<description>Yes! Thanks I actually came to that conclusion last night doing a little &quot;fiddling.&quot;

So if I am thinking this out correctly. The for loop will continuously run when you click on one of the toggles until all of the divs get met with one of the &quot;if&quot;, or &quot;else&quot; statements. And that would be 6 divs each time.

Does that make sense or do I need to rethink this? 

Btw, I have to thank you for being such a great help!</description>
		<content:encoded><![CDATA[<p>Yes! Thanks I actually came to that conclusion last night doing a little &#8220;fiddling.&#8221;</p>
<p>So if I am thinking this out correctly. The for loop will continuously run when you click on one of the toggles until all of the divs get met with one of the &#8220;if&#8221;, or &#8220;else&#8221; statements. And that would be 6 divs each time.</p>
<p>Does that make sense or do I need to rethink this? </p>
<p>Btw, I have to thank you for being such a great help!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: axl163</title>
		<link>http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/comment-page-4/#comment-65042</link>
		<dc:creator>axl163</dc:creator>
		<pubDate>Sat, 17 Dec 2011 07:21:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/#comment-65042</guid>
		<description>Hi MrThomas,

&lt;code&gt;newboxes&lt;/code&gt; is the set elements in an array that is returned by the &lt;code&gt;.getElementsByClassName()&lt;/code&gt; function.  The &lt;code&gt;.length&lt;/code&gt; property will return the number of elements of an array so &lt;code&gt;newboxes.length&lt;/code&gt; is simply the number of elements that is matched by class name.

I hope that answers your question.

Allen</description>
		<content:encoded><![CDATA[<p>Hi MrThomas,</p>
<p><code>newboxes</code> is the set elements in an array that is returned by the <code>.getElementsByClassName()</code> function.  The <code>.length</code> property will return the number of elements of an array so <code>newboxes.length</code> is simply the number of elements that is matched by class name.</p>
<p>I hope that answers your question.</p>
<p>Allen</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: MrThomas</title>
		<link>http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/comment-page-4/#comment-65040</link>
		<dc:creator>MrThomas</dc:creator>
		<pubDate>Sat, 17 Dec 2011 07:11:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/#comment-65040</guid>
		<description>What exactly does newbox.length mean?

In detail would be much appreciated. 

Thanks!</description>
		<content:encoded><![CDATA[<p>What exactly does newbox.length mean?</p>
<p>In detail would be much appreciated. </p>
<p>Thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Allen Liu</title>
		<link>http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/comment-page-4/#comment-61822</link>
		<dc:creator>Allen Liu</dc:creator>
		<pubDate>Fri, 09 Dec 2011 00:58:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/#comment-61822</guid>
		<description>I found an error with your body load statement.  Many of your arguments are missing the left single quote:

&lt;pre&gt;
onLoad=&quot;MM_preloadImages(Images/Rollover_03.png&#039;,Images/Rollover_05.png&#039;...);
&lt;/pre&gt;

As you can see the &lt;code&gt;Images/Rollover_03.png&lt;/code&gt; is missing the left single.  This goes on for most of the arguments you have in that list

Allen</description>
		<content:encoded><![CDATA[<p>I found an error with your body load statement.  Many of your arguments are missing the left single quote:</p>
<pre>
onLoad="MM_preloadImages(Images/Rollover_03.png',Images/Rollover_05.png'...);
</pre>
<p>As you can see the <code>Images/Rollover_03.png</code> is missing the left single.  This goes on for most of the arguments you have in that list</p>
<p>Allen</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Allen Liu</title>
		<link>http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/comment-page-4/#comment-61818</link>
		<dc:creator>Allen Liu</dc:creator>
		<pubDate>Fri, 09 Dec 2011 00:54:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/#comment-61818</guid>
		<description>I tried it out and it appears to be working for me.  All 3 divs are showing after it is finished loading.  Then it just shows the selected one when you starting clicking on the icons.  Is that what you are trying to accomplish?

Allen</description>
		<content:encoded><![CDATA[<p>I tried it out and it appears to be working for me.  All 3 divs are showing after it is finished loading.  Then it just shows the selected one when you starting clicking on the icons.  Is that what you are trying to accomplish?</p>
<p>Allen</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt</title>
		<link>http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/comment-page-4/#comment-61814</link>
		<dc:creator>Matt</dc:creator>
		<pubDate>Fri, 09 Dec 2011 00:51:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/#comment-61814</guid>
		<description>Tried it and it isn&#039;t working.  If you can make this work I will buy you some coffee! Peets.com style~!

http://tinyurl.com/cw5jsks</description>
		<content:encoded><![CDATA[<p>Tried it and it isn&#8217;t working.  If you can make this work I will buy you some coffee! Peets.com style~!</p>
<p><a href="http://tinyurl.com/cw5jsks" rel="nofollow">http://tinyurl.com/cw5jsks</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt</title>
		<link>http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/comment-page-4/#comment-61810</link>
		<dc:creator>Matt</dc:creator>
		<pubDate>Fri, 09 Dec 2011 00:30:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/#comment-61810</guid>
		<description>O geez, and I thought it would be javascript base.  I feel silly.  Thank you!</description>
		<content:encoded><![CDATA[<p>O geez, and I thought it would be javascript base.  I feel silly.  Thank you!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Allen Liu</title>
		<link>http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/comment-page-4/#comment-61105</link>
		<dc:creator>Allen Liu</dc:creator>
		<pubDate>Wed, 07 Dec 2011 09:07:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/#comment-61105</guid>
		<description>Hi Matt,

If you want all your divs to not be displayed on the initial load, you can simply give them a class and the following in your CSS:
&lt;pre lang=&quot;css&quot;&gt;
.yourClass {
    display: none;
}
&lt;/pre&gt;

Allen</description>
		<content:encoded><![CDATA[<p>Hi Matt,</p>
<p>If you want all your divs to not be displayed on the initial load, you can simply give them a class and the following in your CSS:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.yourClass</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Allen</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt</title>
		<link>http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/comment-page-4/#comment-61001</link>
		<dc:creator>Matt</dc:creator>
		<pubDate>Wed, 07 Dec 2011 03:30:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/#comment-61001</guid>
		<description>Allen:

The example of &quot;only one div is displayed at any one time&quot; was exactly what I was looking to build for a website I was designing.  Thank you!  I had a small tweek that I would love your input on, but I am unsure on how to edit what you already created.  The edit would be when the page is first loaded the DIV#1, DIV#2, and DIV#3 are not displayed at all, only when clicking the specific toggle link would the DIV text display in the same fashion of one at a time.</description>
		<content:encoded><![CDATA[<p>Allen:</p>
<p>The example of &#8220;only one div is displayed at any one time&#8221; was exactly what I was looking to build for a website I was designing.  Thank you!  I had a small tweek that I would love your input on, but I am unsure on how to edit what you already created.  The edit would be when the page is first loaded the DIV#1, DIV#2, and DIV#3 are not displayed at all, only when clicking the specific toggle link would the DIV text display in the same fashion of one at a time.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Allen Liu</title>
		<link>http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/comment-page-4/#comment-56738</link>
		<dc:creator>Allen Liu</dc:creator>
		<pubDate>Fri, 25 Nov 2011 23:21:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/#comment-56738</guid>
		<description>Yikes!  I&#039;ll roll back the post.  I honestly think the best way to go about this is to use jQuery which should take care of the browser compatibility issues.

Allen</description>
		<content:encoded><![CDATA[<p>Yikes!  I&#8217;ll roll back the post.  I honestly think the best way to go about this is to use jQuery which should take care of the browser compatibility issues.</p>
<p>Allen</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Russ</title>
		<link>http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/comment-page-4/#comment-56734</link>
		<dc:creator>Russ</dc:creator>
		<pubDate>Fri, 25 Nov 2011 23:14:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/#comment-56734</guid>
		<description>Allen - thanks for new shortened script - works fine, but (arrgghhh!) not in Internet Explorer. (&quot;Object doesn&#039;t support this property or method.&quot;)</description>
		<content:encoded><![CDATA[<p>Allen &#8211; thanks for new shortened script &#8211; works fine, but (arrgghhh!) not in Internet Explorer. (&#8220;Object doesn&#8217;t support this property or method.&#8221;)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: axl163</title>
		<link>http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/comment-page-4/#comment-56722</link>
		<dc:creator>axl163</dc:creator>
		<pubDate>Fri, 25 Nov 2011 22:31:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/#comment-56722</guid>
		<description>Hi Russ,

Here is an example:

HTML code:
&lt;pre lang=&quot;html&quot; line=&quot;1&quot;&gt;
&lt;table&gt;
   &lt;tr&gt;
      &lt;td&gt;
         &lt;div style=&quot;border: 1px solid blue; background-color: #99CCFF; padding: 5px;&quot;&gt;
            &lt;a id=&quot;myHeader1&quot; href=&quot;javascript:showonlyone(&#039;newboxes1&#039;);&quot;  rel=&quot;nofollow&quot;&gt;collapse&lt;/a&gt;
         &lt;/div&gt;
         &lt;div class=&quot;newboxes&quot; id=&quot;newboxes1&quot; style=&quot;border: 1px solid black; background-color: #CCCCCC; display: block;padding: 5px;&quot;&gt;Div #1&lt;/div&gt;
      &lt;/td&gt;
      &lt;td&gt;
         &lt;div style=&quot;border: 1px solid blue; background-color: #99CCFF; padding: 5px;&quot;&gt;
            &lt;a id=&quot;myHeader2&quot; href=&quot;javascript:showonlyone(&#039;newboxes2&#039;);&quot;  rel=&quot;nofollow&quot;&gt;collapse&lt;/a&gt;
         &lt;/div&gt;
         &lt;div class=&quot;newboxes&quot; id=&quot;newboxes2&quot; style=&quot;border: 1px solid black; background-color: #CCCCCC; display: none;padding: 5px;&quot;&gt;Div #2&lt;/div&gt;
      &lt;/td&gt;
      &lt;td&gt;
         &lt;div style=&quot;border: 1px solid blue; background-color: #99CCFF; padding: 5px;&quot;&gt;
            &lt;a id=&quot;myHeader3&quot; href=&quot;javascript:showonlyone(&#039;newboxes3&#039;);&quot;  rel=&quot;nofollow&quot;&gt;collapse&lt;/a&gt;
         &lt;/div&gt;
         &lt;div class=&quot;newboxes&quot; id=&quot;newboxes3&quot; style=&quot;border: 1px solid black; background-color: #CCCCCC; display: none;padding: 5px;&quot;&gt;Div #3&lt;/div&gt;
      &lt;/td&gt;
   &lt;/tr&gt;
&lt;/table&gt;
&lt;/pre&gt;

JavaScript code:
&lt;pre lang=&quot;javascript&quot; line=&quot;1&quot;&gt;
function showonlyone(thechosenone) {
    var newboxes = document.getElementsByClassName(&quot;newboxes&quot;);
        for(var x=0; x&lt;newboxes.length; x++) {
            if (newboxes[x].id == thechosenone) {
                newboxes[x].style.display = &#039;block&#039;;
            }
            else {
                newboxes[x].style.display = &#039;none&#039;;
            }
      }
}
&lt;/pre&gt;

Here is a working example of the code: 

http://jsfiddle.net/Fh7YA/7/

I have even edited the post with this code as it is actually a bit more efficient.

I hope this helps.

Allen</description>
		<content:encoded><![CDATA[<p>Hi Russ,</p>
<p>Here is an example:</p>
<p>HTML code:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;table&gt;
   &lt;tr&gt;
      &lt;td&gt;
         &lt;div style=&quot;border: 1px solid blue; background-color: #99CCFF; padding: 5px;&quot;&gt;
            &lt;a id=&quot;myHeader1&quot; href=&quot;javascript:showonlyone('newboxes1');&quot;  rel=&quot;nofollow&quot;&gt;collapse&lt;/a&gt;
         &lt;/div&gt;
         &lt;div class=&quot;newboxes&quot; id=&quot;newboxes1&quot; style=&quot;border: 1px solid black; background-color: #CCCCCC; display: block;padding: 5px;&quot;&gt;Div #1&lt;/div&gt;
      &lt;/td&gt;
      &lt;td&gt;
         &lt;div style=&quot;border: 1px solid blue; background-color: #99CCFF; padding: 5px;&quot;&gt;
            &lt;a id=&quot;myHeader2&quot; href=&quot;javascript:showonlyone('newboxes2');&quot;  rel=&quot;nofollow&quot;&gt;collapse&lt;/a&gt;
         &lt;/div&gt;
         &lt;div class=&quot;newboxes&quot; id=&quot;newboxes2&quot; style=&quot;border: 1px solid black; background-color: #CCCCCC; display: none;padding: 5px;&quot;&gt;Div #2&lt;/div&gt;
      &lt;/td&gt;
      &lt;td&gt;
         &lt;div style=&quot;border: 1px solid blue; background-color: #99CCFF; padding: 5px;&quot;&gt;
            &lt;a id=&quot;myHeader3&quot; href=&quot;javascript:showonlyone('newboxes3');&quot;  rel=&quot;nofollow&quot;&gt;collapse&lt;/a&gt;
         &lt;/div&gt;
         &lt;div class=&quot;newboxes&quot; id=&quot;newboxes3&quot; style=&quot;border: 1px solid black; background-color: #CCCCCC; display: none;padding: 5px;&quot;&gt;Div #3&lt;/div&gt;
      &lt;/td&gt;
   &lt;/tr&gt;
&lt;/table&gt;</pre></td></tr></table></div>

<p>JavaScript code:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> showonlyone<span style="color: #009900;">&#40;</span>thechosenone<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> newboxes <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementsByClassName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;newboxes&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> x<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> x<span style="color: #339933;">&lt;</span>newboxes.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> x<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>newboxes<span style="color: #009900;">&#91;</span>x<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">id</span> <span style="color: #339933;">==</span> thechosenone<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                newboxes<span style="color: #009900;">&#91;</span>x<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">style</span>.<span style="color: #660066;">display</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'block'</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
                newboxes<span style="color: #009900;">&#91;</span>x<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">style</span>.<span style="color: #660066;">display</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'none'</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Here is a working example of the code: </p>
<p><a href="http://jsfiddle.net/Fh7YA/7/" rel="nofollow">http://jsfiddle.net/Fh7YA/7/</a></p>
<p>I have even edited the post with this code as it is actually a bit more efficient.</p>
<p>I hope this helps.</p>
<p>Allen</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Russ</title>
		<link>http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/comment-page-4/#comment-56713</link>
		<dc:creator>Russ</dc:creator>
		<pubDate>Fri, 25 Nov 2011 22:04:01 +0000</pubDate>
		<guid isPermaLink="false">http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/#comment-56713</guid>
		<description>Thanks Allen, but I&#039;m not sure I understand - swapping &#039;name&#039; for &#039;class&#039; in the html upsets alignment with the script, and I&#039;ve tried tinkering with the script, but to no avail. Could you give an example substitute script which avoids &#039;name&#039;?

Russ

P.S. I agree about the JQuery route being simpler, but I&#039;d like to get my head around this page&#039;s examples first.</description>
		<content:encoded><![CDATA[<p>Thanks Allen, but I&#8217;m not sure I understand &#8211; swapping &#8216;name&#8217; for &#8216;class&#8217; in the html upsets alignment with the script, and I&#8217;ve tried tinkering with the script, but to no avail. Could you give an example substitute script which avoids &#8216;name&#8217;?</p>
<p>Russ</p>
<p>P.S. I agree about the JQuery route being simpler, but I&#8217;d like to get my head around this page&#8217;s examples first.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: axl163</title>
		<link>http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/comment-page-4/#comment-56700</link>
		<dc:creator>axl163</dc:creator>
		<pubDate>Fri, 25 Nov 2011 21:37:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/#comment-56700</guid>
		<description>Hi Russ,

Yes, instead of using the &quot;name&quot; attribute, you can use the &quot;class&quot; attribute =)  I would definitely combine this with the jQuery example though because it will be much simpler and elegant.

Allen</description>
		<content:encoded><![CDATA[<p>Hi Russ,</p>
<p>Yes, instead of using the &#8220;name&#8221; attribute, you can use the &#8220;class&#8221; attribute =)  I would definitely combine this with the jQuery example though because it will be much simpler and elegant.</p>
<p>Allen</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Russ</title>
		<link>http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/comment-page-4/#comment-56696</link>
		<dc:creator>Russ</dc:creator>
		<pubDate>Fri, 25 Nov 2011 21:31:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/#comment-56696</guid>
		<description>Allen - it works great, but the html in the &#039;only one&#039; examples, either on this page or on your newer jQuery page, doesn&#039;t validate because the divs are named (e.g. div name=&quot;newboxes&quot;). Divs shouldn&#039;t be named. Is there a workaround?</description>
		<content:encoded><![CDATA[<p>Allen &#8211; it works great, but the html in the &#8216;only one&#8217; examples, either on this page or on your newer jQuery page, doesn&#8217;t validate because the divs are named (e.g. div name=&#8221;newboxes&#8221;). Divs shouldn&#8217;t be named. Is there a workaround?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: flash_us</title>
		<link>http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/comment-page-4/#comment-56740</link>
		<dc:creator>flash_us</dc:creator>
		<pubDate>Wed, 23 Nov 2011 04:12:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/#comment-56740</guid>
		<description>How to hide, show, or toggle your div http://t.co/c4TfUPqF</description>
		<content:encoded><![CDATA[<p>How to hide, show, or toggle your div <a href="http://t.co/c4TfUPqF" rel="nofollow">http://t.co/c4TfUPqF</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Allen Liu</title>
		<link>http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/comment-page-4/#comment-55615</link>
		<dc:creator>Allen Liu</dc:creator>
		<pubDate>Tue, 22 Nov 2011 23:49:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/#comment-55615</guid>
		<description>You&#039;re Welcome You&#039;re Welcome You&#039;re Welcome! =)

Allen</description>
		<content:encoded><![CDATA[<p>You&#8217;re Welcome You&#8217;re Welcome You&#8217;re Welcome! =)</p>
<p>Allen</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: dustinalan</title>
		<link>http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/comment-page-4/#comment-55611</link>
		<dc:creator>dustinalan</dc:creator>
		<pubDate>Tue, 22 Nov 2011 23:32:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/#comment-55611</guid>
		<description>Thank You Thank You Thank You!! After hours of searching the web and multiple failed JS Attempts. Tons of bulky code. Your simple code took only a few minutes to implement and it is exactly what I needed!! Thank You!!!!!</description>
		<content:encoded><![CDATA[<p>Thank You Thank You Thank You!! After hours of searching the web and multiple failed JS Attempts. Tons of bulky code. Your simple code took only a few minutes to implement and it is exactly what I needed!! Thank You!!!!!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Allen Liu</title>
		<link>http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/comment-page-4/#comment-55326</link>
		<dc:creator>Allen Liu</dc:creator>
		<pubDate>Tue, 22 Nov 2011 02:36:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/#comment-55326</guid>
		<description>Hi Mike,

I can definitely take a look at your issue.  Can you give me a link to the page with the problem? 

Allen</description>
		<content:encoded><![CDATA[<p>Hi Mike,</p>
<p>I can definitely take a look at your issue.  Can you give me a link to the page with the problem? </p>
<p>Allen</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mike</title>
		<link>http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/comment-page-4/#comment-55273</link>
		<dc:creator>mike</dc:creator>
		<pubDate>Mon, 21 Nov 2011 22:57:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/#comment-55273</guid>
		<description>hi.. I&#039;m working on a project and it involves hiding and showing many div&#039;s 
i have tried you method and i can say it works for the most part but i do have bugs.
the div&#039;s that I&#039;m trying to show are all animated with JS them selves so its creating a conflict with this method.

long story short, I&#039;m willing to pay $$ if this problem could be fixed.
please let me know if you&#039;re interested  ... 

thanks in advance.</description>
		<content:encoded><![CDATA[<p>hi.. I&#8217;m working on a project and it involves hiding and showing many div&#8217;s<br />
i have tried you method and i can say it works for the most part but i do have bugs.<br />
the div&#8217;s that I&#8217;m trying to show are all animated with JS them selves so its creating a conflict with this method.</p>
<p>long story short, I&#8217;m willing to pay $$ if this problem could be fixed.<br />
please let me know if you&#8217;re interested  &#8230; </p>
<p>thanks in advance.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Erin</title>
		<link>http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/comment-page-4/#comment-50379</link>
		<dc:creator>Erin</dc:creator>
		<pubDate>Sat, 05 Nov 2011 16:25:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/#comment-50379</guid>
		<description>2 more errors! :(

Error Line 61, Column 30: element &quot;q.length&quot; undefined (this is another semicolon issue, I think).

      for(var x=0; x&lt;q.length; x++) {

and

Line 61, Column 21: start tag was here (it&#039;s looking at the &quot;&lt;&quot; between x and q)

      for(var x=0; x&lt;q.length; x++) {</description>
		<content:encoded><![CDATA[<p>2 more errors! :(</p>
<p>Error Line 61, Column 30: element &#8220;q.length&#8221; undefined (this is another semicolon issue, I think).</p>
<p>      for(var x=0; x&lt;q.length; x++) {</p>
<p>and</p>
<p>Line 61, Column 21: start tag was here (it&#039;s looking at the &quot;&lt;&quot; between x and q)</p>
<p>      for(var x=0; x&lt;q.length; x++) {</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Erin</title>
		<link>http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/comment-page-4/#comment-50376</link>
		<dc:creator>Erin</dc:creator>
		<pubDate>Sat, 05 Nov 2011 15:59:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/#comment-50376</guid>
		<description>One more question!

I&#039;m doing w3c validation, and in line 4 below (      for(var x=0; x&lt;Q.length; x++) { ) it says the semicolon isn&#039;t allowed.

I tried removing it, and of course the script no longer works. Is there something I can do to make this pass w3c validation?

Thanks again!


function question(clicked) {
      var Q = document.getElementsByTagName(&quot;div&quot;);
      for(var x=0; x&lt;Q.length; x++) {
            name = Q[x].getAttribute(&quot;name&quot;);
            if (name == &#039;Q&#039;) {
                  if (Q[x].id == clicked) {
                        if (Q[x].style.display == &#039;block&#039;) {
                              Q[x].style.display = &#039;none&#039;;
                        }
                        else {
                              Q[x].style.display = &#039;block&#039;;
                        }
                  }else {
                        Q[x].style.display = &#039;none&#039;;
                  }
            }
      }
}
</description>
		<content:encoded><![CDATA[<p>One more question!</p>
<p>I&#8217;m doing w3c validation, and in line 4 below (      for(var x=0; x&lt;Q.length; x++) { ) it says the semicolon isn&#039;t allowed.</p>
<p>I tried removing it, and of course the script no longer works. Is there something I can do to make this pass w3c validation?</p>
<p>Thanks again!</p>
<p>function question(clicked) {<br />
      var Q = document.getElementsByTagName(&#8220;div&#8221;);<br />
      for(var x=0; x&lt;Q.length; x++) {<br />
            name = Q[x].getAttribute(&quot;name&quot;);<br />
            if (name == &#039;Q&#039;) {<br />
                  if (Q[x].id == clicked) {<br />
                        if (Q[x].style.display == &#039;block&#039;) {<br />
                              Q[x].style.display = &#039;none&#039;;<br />
                        }<br />
                        else {<br />
                              Q[x].style.display = &#039;block&#039;;<br />
                        }<br />
                  }else {<br />
                        Q[x].style.display = &#039;none&#039;;<br />
                  }<br />
            }<br />
      }<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Allen Liu</title>
		<link>http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/comment-page-4/#comment-50247</link>
		<dc:creator>Allen Liu</dc:creator>
		<pubDate>Fri, 04 Nov 2011 22:02:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/#comment-50247</guid>
		<description>No problem =)</description>
		<content:encoded><![CDATA[<p>No problem =)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steeve</title>
		<link>http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/comment-page-4/#comment-50238</link>
		<dc:creator>Steeve</dc:creator>
		<pubDate>Fri, 04 Nov 2011 21:40:01 +0000</pubDate>
		<guid isPermaLink="false">http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/#comment-50238</guid>
		<description>OH MAN THANK YOU SO MUCH, I&#039;ve been looking for a simplistic way to display only one div at a time for almost a week now.</description>
		<content:encoded><![CDATA[<p>OH MAN THANK YOU SO MUCH, I&#8217;ve been looking for a simplistic way to display only one div at a time for almost a week now.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: How to make more information appear when an icon or text is clicked in html? - Digiscrap Boutique: Digital Scrapbooking Tips and Tricks</title>
		<link>http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/comment-page-4/#comment-49665</link>
		<dc:creator>How to make more information appear when an icon or text is clicked in html? - Digiscrap Boutique: Digital Scrapbooking Tips and Tricks</dc:creator>
		<pubDate>Tue, 01 Nov 2011 03:56:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/#comment-49665</guid>
		<description>[...] jQuery - more and less Hide a DIV - Real&#039;s Javascript How-to Show hide content with sliding effect How to hide, show, or toggle your div Show and Hide Blocks of Text (or Images) with CSS and JavaScript - Toggle DIV Visibility - [...]</description>
		<content:encoded><![CDATA[<p>[...] jQuery &#8211; more and less Hide a DIV &#8211; Real&#039;s Javascript How-to Show hide content with sliding effect How to hide, show, or toggle your div Show and Hide Blocks of Text (or Images) with CSS and JavaScript &#8211; Toggle DIV Visibility &#8211; [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jos</title>
		<link>http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/comment-page-4/#comment-49408</link>
		<dc:creator>Jos</dc:creator>
		<pubDate>Sat, 29 Oct 2011 16:17:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/#comment-49408</guid>
		<description>Works Great! Thank you!</description>
		<content:encoded><![CDATA[<p>Works Great! Thank you!</p>
]]></content:encoded>
	</item>
</channel>
</rss>

