To hide/show area of web page without re-loading a page

CK CK 3788 
Created at
Updated at  
1,019 0 0

You can simply show and hide by changing style.display property. By calling below javascript function from the header row of your table, you can make your table collapsible.

 

<script language="text/javascript">
function ExpandCollapseTable(titleRow)
{
  if(titleRow.parentNode.childNodes.length > 1)
  {
    if(titleRow.parentNode.childNodes[1].style.display=="block" || titleRow.parentNode.childNodes[1].style.display=="")
    {
     for(var i=1;i<titleRow.parentNode.childNodes.length;i++)
     {
       titleRow.parentNode.childNodes[i].style.display = "none";
     }
    }
    else
    {
     for(var i=1;i<titleRow.parentNode.childNodes.length;i++)
     {
       titleRow.parentNode.childNodes[i].style.display = "block";
     }
    }
  }
}
</script>


Following is HTML body calling above function.
 

<body>
  <table border=1>
    <tr onclick="ExpandCollapseTable(this);" style="cursor:pointer;">
      <td colspan=3>
        Table Header(click to expand-collapse)
      </td>
    </tr>
    <tr>
      <td style="width: 100px">1</td>
      <td style="width: 100px">2</td>
      <td style="width: 100px">3</td>
    </tr>
    <tr>
      <td style="width: 100px">4</td>
      <td style="width: 100px">5</td>
      <td style="width: 100px">6</td>
    </tr>
    <tr>
      <td style="width: 100px">7</td>
      <td style="width: 100px">8</td>
      <td style="width: 100px">9</td>
    </tr>
  </table>
</body>
Tags Compare Table ExpandCollapseTable HTML Javascript style style.display Facebook X
Comments 0
Similar posts
  1. Displays the html tags without rendering on a webpage
    350
  2. Javascript based query parser for AJAX application
    564
  3. To compare two HTML tables on web page in real time
    514
  4. To get web browser capability
    522
  5. Photo thumbnail viewer implemented in javascript
    482
  6. Javascript Confirmation
    589
  7. Javascript Prompts
    448
  8. How to know browser version in javascript ?
    439
  9. How to know the browser name in Javascript ?
    639
  10. Select All, None, Invert checkbox
    504
  11. Photoshop script programming in Javascript
    531
  12. Simple RSS Reader based on javascript
    501
  13. How to find the ip address of a client machine from a web application?
    518
  14. Clipboard copy function working
    3,353
  15. IFRAME Auto Resize in IE, FireFox by Javascript
    454
  16. How to include Javascript from anonther ?
    409
  17. Javascript based Browser Sniffing
    430
  18. Javascript based Regular Expression Tester
    372
  19. Two useful string functions - substr & substring
    404
  20. Is there URLEncode function in Javascript ?
    390
  21. Move window
    545
  22. How to calculate page loading time ?
    358
  23. Number Of Vists
    507
  24. Add Message On Mouse Traling
    2,545
  25. Tooltip
    407
  26. Document Fader
    346
  27. Book Mark This Site
    403
  28. Icon Coupled Url
    425
  29. Button That Will Close The Browser Window
    349
  30. Button That Will Show The Page's Source
    385
  1. Understanding Elasticsearch from Installation to Trouble Shooting
    909
  2. IndexNow for better SEO
    316
  3. Enhancing SEO for Single Page Applications: Implementing Dynamic URL Updates
    1,037
  4. Method to ignore JavaScript Errors globally instead of try... catch for each of cases
    968
  5. Method to catch the browser console log and errors for remote web debugging
    2,166
  6. Atlassian Jira Ticket API Response Example
    2,748
  7. Three different type of Word-Wrap options in HTML CSS
    1,181
  8. JavaScript code to load XML Document
    601
  9. Creating a Pinterest-Style Card Layout with Bootstrap and Masonry
    589
  10. Equal Height Blocks in Bootstrap with JavaScript
    708
  11. Copy text to clipboard in Javascript
    1,714
  12. To block copy & paste on your blog content
    899
  13. Shake your browser window by Javascript
    933
  14. Photoshop script programming in Javascript
    531
  15. To compare two HTML tables on web page in real time
    514
  16. Displays the html tags without rendering on a webpage
    350
  17. Javascript based query parser for AJAX application
    564
  18. To get web browser capability
    522
  19. Photo thumbnail viewer implemented in javascript
    482
  20. Javascript Confirmation
    589
  21. Javascript Prompts
    448
  22. How to know browser version in javascript ?
    439
  23. How to know the browser name in Javascript ?
    639
  24. Select All, None, Invert checkbox
    504
  25. Simple RSS Reader based on javascript
    501
  26. How to find the ip address of a client machine from a web application?
    518
  27. Put Date Time on HTML
    550
  28. IFRAME Auto Resize in IE, FireFox by Javascript
    454
  29. How to elimiate the "Restore Previous Session" dialog when FireFox 2.0 starts
    407
  30. How to include Javascript from anonther ?
    409
Recently updated
  1. Why 100% SEO Guarantees Better User Engagement and How to Achieve It in Your Service
    27
  2. Why SPF and DKIM Are Essential for Linux Email Servers?
    24
  3. How do I create animated background for Google Meet?
    19,712
  4. MaxMind GeoLite2 vs. DB-IP Lite vs. ip-api.com: Choosing the Right Free IP Geolocation Solution
    217
  5. Meet Valkey: Why Redis Changed Its License, Why Valkey is Better, and How to Use It as a Drop-in Replacement
    85
  6. How Rogue Web Scrapers Are Stealing My Content and Destroying My Server
    153
  7. Array of arguments passed to script in PHP
    85
  8. Invalid Auction Storms in Ad Tech
    93
  9. Building MRC-Compliant Instrumentation in Ad Tech: Implementation Steps and Key Challenges
    198
  10. The Two Clocks of Ad Server Architecture
    63
  11. Frequency Cap Architecture Overview
    509
  12. Collecting Proof-of-Play from 100,000 Screens
    141
  13. Vector Search in Relational Databases (RDBs): Trends & Usage Environments
    280
  14. What is RedisVL?
    105
  15. Designing a Skill Registry Architecture: Minimize Token Usage and Maximize AI Performance
    224
  16. TPU & GPU Cluster Management Tools
    232
  17. The Concept of Scaffolding in AI Agents
    221
  18. Beyond Static Pipelines: Architecting LLM Multi-Agent Systems for Autonomous Workflow Orchestration
    576
  19. AI-DLC vs. AI-SDLC: Model-Centric vs. System-Centric AI Development
    253
  20. Fine-Tuning Open-Weight LLMs: Training, Licensing, and Deploying Custom Models with Ollama
    327
  21. Inside the Next-Generation Streaming Architecture: Ultra-Low Latency, SGAI, and AI Codecs
    197
  22. Machine Learning: Training vs. Ranking
    213
  23. The Continuous Learning Machine: Designing a Loop That Actually Turns
    217
  24. The Next-Gen Low-Latency Standards: LL-HLS & MoQ
    189
  25. Designing a Data Curation System Around a Vector Database
    215
  26. Extracting Context from Live Video: The Architecture Got Simpler When We Stopped Building Features
    229
  27. The New Ad Stack Behind Live Sports Streaming: Inside SGAI, EABN, and the Standards Race to Fix Live Monetization
    649
  28. Designing MLOps Architectures to Handle Seasonal Data Drift in EV Fleet Models
    185
  29. From 15 to 40+ FPS: Accelerating PyTorch Object Detection on Automotive ECUs
    207
  30. Understanding Data Lineage
    252