Hi,
I am using Expand/Collapse functionality for the table. By default it is expandable. I want to do it is by default Collapsed. Below is the code for it. Please help me in this.
<script>
<!--
function expandCollapse() {
// Get the parent table
var table = this.parentNode;
if(table.tagName.match(/^table$/i)) { // Check it is indeed a table
// Go through each row, hiding it or showing it...
var tableBody = table.getElementsByTagName('tbody')[0];
var bodyRows = tableBody.getElementsByTagName('tr');
for(var rowsI = 0; rowsI < bodyRows.length; rowsI++) {
if(this.className == 'collapse') bodyRows[rowsI].className = 'hidden';
else if(this.className == 'expand') bodyRows[rowsI].className = '';
}
function collapsibleTables() {
// Find all the tables in the document
var allTables = document.getElementsByTagName('table');
// go through each table
for(var tablesI = 0; tablesI < allTables.length; tablesI++) {
// Find the head section
var head = allTables[tablesI].getElementsByTagName('thead')[0];
if(head) {
// Change it's class, and give it an onclick
head.className = "collapse";
head.onclick = expandCollapse;
}
}
}
window.onload = function() {
// All the things to do when the window loads
collapsibleTables();
}
-->
</script>
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<thead>
<tr><td>Results of an experiment</td></tr>
</thead>
<tbody>
<tr><td>1</td></tr>
<tr><td>2</td></tr>
<tr><td>3</td></tr>
<tr>
<td>
<table>
<thead><tr><td>result 4 has several branches</td></tr></thead>
<tbody>
<tr><td>1</td></tr>
<tr><td>2</td></tr>
<tr><td>2</td></tr>
</tbody>
</table>
</td>
</tr>
<tr><td>5</td></tr>
<tr><td>6</td></tr>
<tr>
<td>
<table>
<thead><tr><td>result 7 has several branches</td></tr></thead>
<tbody>
<tr><td>1</td></tr>
<tr><td>2</td></tr>
<tr><td>2</td></tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</body>
</html>
Expand/Collapse How To make hide all the tbody in onload function
Hi Philips, Thanks for your reply....I have tried with that code. It did not work for me..... By default it should be hidden in onload function. When I click + button then it should expand all the rows....
Bookmarks