How do I iterate nameless elements

Posted on 2006-03-24
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)?

Question by:CycnoAB
  • 2
  • 2
LVL 49

Accepted Solution

Roonaan earned 500 total points
ID: 16280607
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.



Author Comment

ID: 16281237
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?
LVL 49

Expert Comment

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

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


Author Comment

ID: 16281452
What's the pro:s of using them?
Are there any requirements to use them btw, since it's not working for me?

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question