473,395 Members | 1,488 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Table with collapsing rows

Hi everyone,
I write a simple javascript to expand / collapse some rows of a table.
The problem is that when I click more than one time the link to expand
/collapse the rows I get an unwanted extra space after such rows.
Can anyone help me to solve the problem (I use Firefox to test this
code)?
Here there is the sample code:

<html>
<head>
<script type="text/javascript">
function setTableRowClass(currentNode){
// get child nodes of tbody tag
var rowToHide =
currentNode.parentNode.parentNode.parentNode.child Nodes;
var aux = 0;
for(var j = 0; j < rowToHide.length; j++)
if(rowToHide[j].tagName == 'TR')
if(aux == 0)
aux = 1; //skip the first 'tr' tag with the link 'Hide details'
else
if(rowToHide[j].style.display == 'none')
rowToHide[j].style.display = 'block'; // show
else
rowToHide[j].style.display = 'none'; // hide
return false;
}
</script>
</head>
<body>
<table style="{border-style: solid;}">
<tbody>
<tr>
<td>
<a href="#" onclick="return setTableRowClass(this);">Click for
details 1</a>
</td>
</tr>
<tr style="display: none;"><td>Details 1</td></tr>
<tr style="display: none;"><td>Details 2</td></tr>
<tr style="display: none;"><td>Details 3</td></tr>
</tbody>
<tbody>
<tr>
<td>
<a href="#" onclick="return setTableRowClass(this);">Click for
details 2</a>
</td>
</tr>
<tr style="display: none;"><td>Details 4</td></tr>
<tr style="display: none;"><td>Details 5</td></tr>
<tr style="display: none;"><td>Details 6</td></tr>
</tbody>
</table>
</body>
</html>

Thanks

Bye,
Alessandro

Nov 20 '06 #1
2 2832
alexyz wrote:

if(rowToHide[j].style.display == 'none')
rowToHide[j].style.display = 'block'; // show
Set the inline display style to '' to show, not to 'block'. Or set to
'table-row', as that is the proper CSS 2 value for table row elements.
Only IE 5/6 do not support that so setting to '' where the default
stylesheet of the browser kicks in is safer.


--

Martin Honnen
http://JavaScript.FAQTs.com/
Nov 20 '06 #2
Martin Honnen wrote:
>
Set the inline display style to '' to show, not to 'block'. Or set to
'table-row', as that is the proper CSS 2 value for table row elements.
Only IE 5/6 do not support that so setting to '' where the default
stylesheet of the browser kicks in is safer.

Thanks a lot Martin ! I waste a lot of time to try to fix this problem.

Bye,
Alessandro

Nov 20 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Spartanicus | last post by:
I've been caught out by what I thought was an Opera 7.5p1 issue: http://www.spartanicus.utvinternet.ie/test/opera7.5p1_css_background_image_issue.htm but as was pointed out to me this is actually...
12
by: Rick DeBay | last post by:
I'm trying to create a layout table, where the spacing between rows varies. I've tried using setting margin-top and border-top for the rows I wan't spaced down from the one above, and I've also...
9
by: Wang, Jay | last post by:
I try to group several rows in a table into a div and show/hide them by click on a button somewhere with a javascript link. When clicked, the link will toggle the style of the div section's style...
4
by: Monte Gardner | last post by:
I'm trying to create an effect wherein an HTML page contains a large number of products (up to 125 possibly). Initially, only the first 3 are displayed. When the user clicks on a 'next' or...
5
by: Borris | last post by:
<div style="background-color: blue; width: 500px; height: 300px"> <div style="background-color: red; margin-top: 100px; margin-left: 100px; width: 300px; height: 100px"> </div> </div> Where...
1
by: yb | last post by:
Hi, I'm looking for clarification of css 2.1 specification in section 8.3.1 "Collapsing Margins" The 6th bullet reads "If the top and bottom margins of a box are adjoining ..." I won't paste...
3
by: Simon Harvey | last post by:
Hi all, Can anyone tell me what the easiest way to achieve a collapsable panel area in a datagrid is? Do I need to find a third party panel control or does the datagrid/gridview somehow support...
5
by: SlowArrow | last post by:
Here collapsing seems to work differently in vb.net 2005 from that I use to see in vb.net 2003: Using the collapsing in vb.net 2003 shows the whole interface of the methods, subroutines,...
1
by: Jahedx99 | last post by:
Check out the site: www.progtalk.com. They have a great article to expand and collapse rows of a grid. The cool part it, that the expanding and collapsing happens using Javascript. I think the...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.