473,809 Members | 2,742 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 setTableRowClas s(currentNode){
// get child nodes of tbody tag
var rowToHide =
currentNode.par entNode.parentN ode.parentNode. childNodes;
var aux = 0;
for(var j = 0; j < rowToHide.lengt h; 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 setTableRowClas s(this);">Click for
details 1</a>
</td>
</tr>
<tr style="display: none;"><td>Deta ils 1</td></tr>
<tr style="display: none;"><td>Deta ils 2</td></tr>
<tr style="display: none;"><td>Deta ils 3</td></tr>
</tbody>
<tbody>
<tr>
<td>
<a href="#" onclick="return setTableRowClas s(this);">Click for
details 2</a>
</td>
</tr>
<tr style="display: none;"><td>Deta ils 4</td></tr>
<tr style="display: none;"><td>Deta ils 5</td></tr>
<tr style="display: none;"><td>Deta ils 6</td></tr>
</tbody>
</table>
</body>
</html>

Thanks

Bye,
Alessandro

Nov 20 '06 #1
2 2849
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
1659
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 a fault in my code which is exposed by the improved CSS standards support in v7.5p1. The top margin on the <h1> collapses with the zero margin on the <body> element to form a single margin equal to the margin specified on the <h1>.
12
39126
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 tried setting it on all of the cells of that row. This hasn't worked, so I was wondering if anyone knew how it could be done. Thanks, Rick DeBay
9
33480
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 between BLOCK and NONE. This technique works on normal text fine, but it doesn't work on part of the table, is there a solution that I can achieve the goal of turning on/off several rows all together? Thanks.
4
2978
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 'previous' button, the currently displayed products dissappear and the next or previous set of 3 appear in the same place. I've got it working in IE 6.0. It's mostly working in Netscape 7.2. The only problem in NS 7.2 is that each time you click on...
5
1898
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 will the red box be positioned? Even experienced web developers often expect it to be in the middle of the blue box, but instead (on standards-compliant browsers) the blue box is lowered to line up its top edge with that of the red box. This is...
1
1741
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 the whole point here, its too long. But, from this first line does this mean that the element has empty
3
3287
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 this functionality inherently? Many thanks to anyone who can advise Simon
5
1969
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, functions, etc, while in vb.net 2005 those parts after the name (arguments, etc) are missing. Is there an option to show them as well, or this is the only working method of the collapsing? What amazed me that the collapsing in the vC.net 2005 shows the...
1
5308
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 exact link is: http://www.progtalk.com/ViewArticle.aspx?ArticleID=1
0
9601
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10637
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10379
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10115
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9199
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5687
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.