Hide Show DIV Content with Links by using Javascript

The Hide and Show DIV elements for HTML content is a great way to clean up your sidebar. It becomes especially handy for those long blogroll lists or anything that clutters up the blog. Just simply click a link to make all the hidden content magically appear and disappear.

Demo:

+/- Click Here to Expand and Collapse



How to use it in Your Blog

Step 1: Adding CSS and Javascript
First, add this code below directly above the </head> tag.

<style type="text/css">
.commenthidden {display:none}
.commentshown {display:inline}
</style>
<script type="text/Javascript">
function togglecomments (postid) {
var whichpost = document.getElementById(postid);
if (whichpost.className=="commentshown") { whichpost.className="commenthidden"; } else { whichpost.className="commentshown"; }
} </script>

Step 2: Adding the Active Content to be Displayed
Place this code wherever you would like it to appear. Make sure to change the red text to a name that is "unique" to any other name in your template. An example might be "blogroll-dropdown". If you do not give each Hide Show DIV element a unique name the script cannot be used more than once on the same page. The green text is the title of the link that you click on to make the content appear. Replace the code "Expanded Content" with the content you wish to have expand and collapse.

<a aiotitle="click to expand" href="javascript:togglecomments('UniqueName')"
>Link Title</a><br />
<div class="commenthidden" id="UniqueName"
>Expanded Content</div>

Step 3: Sample Code
Here is what my code looks like for the demo above:

<a aiotitle="" href="javascript:togglecomments('hideshowdemo')">+/- Click Here to Expand and Collapse</a>
<div class="commenthidden" id="hideshowdemo"><ul><li><a href="http://howhero.com/">HowHero Tutorials</a></li><li><a href="http://widgetsforfree.blogspot.com/2008/09/translate-blog-widget-using-flags.html">Blog Translation Plugin</a></li><li><a href="http://widgetsforfree.blogspot.com/2008/09/make-money-blog-widget-performancing.html">Make Money Widget</a></li></ul>
</div>

This entry was posted in . Bookmark the permalink.

One Response to Hide Show DIV Content with Links by using Javascript

Feedjit

New Page 1

Prestige Temple Bells NITESH CHELSEA Prestige Shantiniketan sale Prestige Kew Gardens Sobha silicon Oasis Sobha Valley View oceanus vista Purva 270 century silicon city nitesh caesars palace nitesh virgin island salarpuria sattva credenza brigade northridge vaswani claremont godrej united prestige gulmohar godrej garden city puravankara between the parks puravankara lalbaghroad purva between the parks provident the tree salarpuria sattva cadenza nitesh virgin island bangalore Godrej Prana Purva The Waves THE PRESIDENTIAL TOWER BANGALORE vaswani exquisite mantri energia prestige leela residences sobha halcyon bhartiya city leela residences lodha codename the central mantri energia bangalore mantri manyata tech park unishir experience unishir verzure mantri energia bangalore godrej sky byculla nitesh grand canyon nitesh rio kanakapura nitesh sloane square Sobha Aspirational Homes sobha golden quadrilateral prestige song of the south prestige kew gardens bangalore ajmera sports city salarpuria sattva east crest old madras road salarpuria sattva east crest salarpuria east crest salarpuria eastcrest sattva east crest godrej sky goyal alanoville salarpuria rhythm Sobha Green Acres Godrej Infinity Keshav Nagar Purva Silver Sands Keshavnagar Puravankara City Of Gold Purva City Of Gold Sobha Dream Acres Sobha Dream Series RMZ Marq RMZ Azure Bangalore Mahindra Windchimes Puravankara Limousine Homes Osadia Garden City Purva Limousine Homes Godrej The Trees Mumbai Prestige Song Of The South Begur Prestige Song Of The South Godrej Infinity Pune Salarpuria Sattva Pipal Tree Salarpuria Pipal Tree Salarpuria Sattva Casa Irene Salarpuria Casa Irene Lodha Codename Concept X Lodha Concept X Salarpuria Sattva Divinity

BTricks