By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,277 Members | 1,505 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,277 IT Pros & Developers. It's quick & easy.

Problem with getting nested tables

P: n/a
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
gt*****@mail.gatech.edu
Nov 23 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a


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/
Nov 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.