We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now


How do I iterate nameless elements

CycnoAB asked
Medium Priority
Last Modified: 2008-03-17
I'm programming an application that displays a list of selected database tulips with some restriction in information due to simplicity in the list. However I got a request to enable an option to "expand" every row, displaying the "short description" of the tulip. Easy enough. Now, when a user select a table row it displays the complete information in another frame and sets the row to selected. This works fine with one row, but with the expanding row I've encountered problems. With my current scipt I only select the first row.
Here's an example:

<tr onmouseover="className='highlight_row';" class="e_r" onmouseout="m_ou(this,'e_r');"onclick="cli(this,'e_r',99,'all');">
      <td width="15" style="padding-left: 2px;">&nbsp;</td>
      <td nowrap>Company name</td>
      <td nowrap>Contract description</td>
      <td align="right"><img title="Copy to clipboard" onclick="cli_copy(99);" height="12" src="../images/copy.gif" width="12">&nbsp;</td>
<tr class='e_r'>
      <td colspan='3'>Expanded description using 3 columns.</td>

Without the expanded row the last TR is not executed.
I realize I might be able to work around this by putting it all into a table in each row in the main table, but my curiousity drives me to see if there is a way to solve this. The javascript function works as follow atm:
function cli(t,r,ci,op)
      -[data removed]-

So, how do I set both rows to selected (and deselect them when a new one is set)?

Watch Question

Top Expert 2006
Not fully sure if this is applicable for your situation, but you should be able to use something like this:

<style type="text/css">
tbody.closed tr.whenOpened {display:none;}
tbody.opened tr.whenClosed {display:none;}

<tbody class="closed">
     <td>This row is always visible</td>
     <td><a href="#" onclick="this.parentNode.parentNode.className='opened';" class="whenClosed">Expand</a></td>
   <tr class="whenOpened">
      <td colspan="2">Detailed description, only visible when tbody class equals 'opened'</td>
<tbody class="closed">
   <!-- another record -->

This way you don't have to mess with div ids and stuff. Also there can be multiple records be opened at the same time.

Hope this helps.


Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts


That was a very interesting piece of code I must admit.
What is the tbody entity you use? Does it work with table, the one I'm accustomed to? Because i tried and nothing happens (used IE and FF).

My problem pretty much comes down to changing class of the following TR class, so I guess I could change the name of the second one. I found a function called nextSibling which works out fine in IE, but not in FF. Is there a similat function to parentNode? Like nextNode or something like that?
Top Expert 2006

<tbody>,<thead>,<tfoot> are table tags using which you can group tr's.

You can have a single thead, multiple tbodys and single tfoot.



What's the pro:s of using them?
Are there any requirements to use them btw, since it's not working for me?
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.