Problem with getting nested tables

Discussion in 'Javascript' started by Joseph Scoccimaro, Nov 12, 2005.

  1. I am currently working on a project for school dealing with accessing
    the DOM. I am trying to get access to inner tables that are nested with
    in other tables. Currently I am able to get all parent tables without a
    problem. When I try to get an inner table through the child nodes it
    says that the tr elements of the parent table are undefined. Posted is
    the code I am using:

    function nestedTableAnalysis()
    {



    DocBodyChildren = document.body.childNodes;
    ParentTableTags = new Array();
    i = 0;

    for(j=0; j< DocBodyChildren.length; j++) {
    if(DocBodyChildren[j].nodeName.toLowerCase() == \"table\") {
    ParentTableTags = DocBodyChildren[j];
    i++;
    }//end if

    }


    for(k = 0; k < ParentTableTags.length; k++ ) {

    childTableAnalysis(ParentTableTags[k].childNodes);

    }


    }//end nestedTableAnalysis()



    function childTableAnalysis(NodesToCheck, tabSpace, periodSpacer)
    {



    j = 1;

    for(i=0; i < NodesToCheck.length; i++) {

    document.writeln(NodesToCheck.nodeName);

    if(NodesToCheck.nodeName == \"TABLE\") {
    document.writeln(\"<p> Table Found!</p>\");


    j++;

    childTableAnalysis(NodesToCheck.childNodes);
    }//end if

    if(NodesToCheck.nodeName == \"TR\") {
    childTableAnalysis(NodesToCheck.childNodes);
    }

    if(NodesToCheck.nodeName == \"TD\") {
    childTableAnalysis(NodesToCheck.childNodes);
    }


    }

    }//end childTableAnalysis

    Thanks,
    Joseph Scoccimaro
    Joseph Scoccimaro, Nov 12, 2005
    #1
    1. Advertising

  2. Joseph Scoccimaro wrote:

    > I am trying to get access to inner tables that are nested with
    > in other tables. Currently I am able to get all parent tables without a
    > problem. When I try to get an inner table through the child nodes it
    > says that the tr elements of the parent table are undefined.


    HTML 4 wants all table elements to have at least one explicit or
    implicit tbody child element and all tr elements are then children of a
    thead or tfoot or tbody but not direct children of the table itself. In
    the HTML DOM a table element object has a property named tBodies which
    is a collection of the explicit and implicit tbody child elements. Use
    that instead of walking childNodes and looking for elements with a
    certain tagName.
    <http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-64060425>
    You can also use the rows collection property of table or tbody or thead
    or tfoot elements:
    <http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-67417573>



    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Nov 12, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Peter Bassett
    Replies:
    3
    Views:
    917
    Augustus
    Aug 15, 2003
  2. Otuatail

    Tables within tables

    Otuatail, Jul 31, 2004, in forum: HTML
    Replies:
    7
    Views:
    486
  3. Octopus0
    Replies:
    2
    Views:
    632
    dorayme
    Mar 30, 2006
  4. Chris Brat
    Replies:
    5
    Views:
    689
    =?iso-8859-1?q?Luis_M._Gonz=E1lez?=
    Aug 22, 2006
  5. Replies:
    3
    Views:
    459
    Victor Bazarov
    Dec 7, 2007
Loading...

Share This Page