How do I iterate nameless elements

Posted on 2006-03-24
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
    LVL 49

    Accepted Solution

    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.


    LVL 3

    Author Comment

    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

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

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

    LVL 3

    Author Comment

    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

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    "That which we persist in doing becomes easier, not that the task itself has become easier, but that our ability to perform it has improved." Ralph Waldo Emerson Introduction: One of the wonderful things about the web is that it makes it s…
    This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
    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…

    734 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

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now