Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Problem with getting nested tables

Reply
Thread Tools

Problem with getting nested tables

 
 
Joseph Scoccimaro
Guest
Posts: n/a
 
      11-12-2005
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[i] = 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[i].nodeName == \"TABLE\") {
document.writeln(\"<p> Table Found!</p>\");


j++;

childTableAnalysis(NodesToCheck[i].childNodes);
}//end if

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

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


}

}//end childTableAnalysis

Thanks,
Joseph Scoccimaro
http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      11-12-2005


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/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Nested friend class in nested template problem tonvandenheuvel@gmail.com C++ 3 12-07-2007 03:02 PM
How to get database metadata information (i.e. existing tables and columns in tables) Chris Brat Python 5 08-22-2006 05:25 PM
Nested Tables Spaces Removal Problem Octopus0 HTML 2 03-30-2006 09:53 PM
Tables within tables Otuatail HTML 7 08-02-2004 04:42 AM
Text after 2 tables actually appears between 2 tables ! Peter Bassett HTML 3 08-15-2003 06:46 PM



Advertisments