DelphiFAQ Home Search:
General :: Web publishing :: JavaScript
Code snippets to add functionality to your HTML pages, preferably cross-browser.


This list is sorted by recent document popularity (not total page views).
New documents will first appear at the bottom.

Featured Article

Dynamically collapse or expand a section of a web page


I want to dynamically collapse or expand a section of a web page. The idea is to show the user a short screen with a few options, and if the user wants to see any detail, then he will click on an "Expand" link and the relevant section will show its details.
This should be done in Javascript, with no extra http page views.


The trick is to put the to-be-collapsed sections in DIV tags.

The code below has a DIV section named 'tbl' which is initially hidden. Then by clicking on a link it can be expanded or hidden again.

Make sure to set the initial style to display:none
<div id=tbl name=tbl style="overflow:hidden;display:none">

 Some text before
 <div id=tbl name=tbl style="overflow:hidden;display:none">
 <table border=1>
 some text after
 <script language="JavaScript" type="text/javascript">
 function sizeTbl(h) {
   var tbl = document.getElementById('tbl'); = h;
 // -->
 <a href="javascript:sizeTbl('none')">Hide</a>
 <a href="javascript:sizeTbl('block')">Expand</a>

Generated 8:01:46 on Apr 1, 2020