473,464 Members | 1,499 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Alternative to "children" property of DOM in firefox

I have the following code

var thisDoc=document.getElementById("myTable"); // myTable is the name
of the table
alert(thisDoc.childNodes[i].children.length)

How do I change the second line of code for it to work in firefox?

Regards,
Angel

Jun 19 '06 #1
10 11297
Angel wrote on 19 jun 2006 in comp.lang.javascript:
I have the following code

var thisDoc=document.getElementById("myTable"); // myTable is the name
of the table
alert(thisDoc.childNodes[i].children.length)

How do I change the second line of code for it to work in firefox?


alert(thisDoc.rows[i].cells.length)

[only partly tested and me not knowing much about FF,
it seems the natural way to DOMinate]

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jun 19 '06 #2
Angel wrote:
I have the following code

var thisDoc=document.getElementById("myTable"); // myTable is the name
of the table
alert(thisDoc.childNodes[i].children.length)

How do I change the second line of code for it to work in firefox?

Regards,
Angel


What about alert(thisDoc.childNodes[i].childNodes.length) ?
And I would expect it to work in IE6 too.
Jun 19 '06 #3
Robert wrote:
Angel wrote:
I have the following code

var thisDoc=document.getElementById("myTable"); // myTable is the name
of the table
alert(thisDoc.childNodes[i].children.length)

How do I change the second line of code for it to work in firefox?

Regards,
Angel


What about alert(thisDoc.childNodes[i].childNodes.length) ?
And I would expect it to work in IE6 too.


Only if thisDoc.childNodes[i] is not a #text node. It will most likely
be a tableSection element - thead, tfoot or tbody - or maybe a caption,
col or colgroup.
--
Rob
Jun 19 '06 #4
Hi,

RobG wrote:
Robert wrote:
Angel wrote:
I have the following code

var thisDoc=document.getElementById("myTable"); // myTable is the name
of the table
alert(thisDoc.childNodes[i].children.length)

How do I change the second line of code for it to work in firefox?

Regards,
Angel


What about alert(thisDoc.childNodes[i].childNodes.length) ?
And I would expect it to work in IE6 too.


Only if thisDoc.childNodes[i] is not a #text node. It will most likely
be a tableSection element - thead, tfoot or tbody - or maybe a caption,
col or colgroup.


That puzzled me too, but then I thought, the problem will be the same
with children, so hopefully the OP knows what he does.

To handle the issue of the text node, I would introduce some simple
checks like this:

if ( thisDoc
&& thisDoc.childNodes
&& thisDoc.childNodes[ i ]
&& thisDoc.childNodes[ i ].childNodes )
{
alert( thisDoc.childNodes[ i ].childNodes.length );
}

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch
Jun 19 '06 #5
Laurent Bugnion wrote:
Hi,

RobG wrote:
Robert wrote:
Angel wrote:
I have the following code

var thisDoc=document.getElementById("myTable"); // myTable is the name
of the table
alert(thisDoc.childNodes[i].children.length)

How do I change the second line of code for it to work in firefox?

Regards,
Angel
What about alert(thisDoc.childNodes[i].childNodes.length) ?
And I would expect it to work in IE6 too.


Only if thisDoc.childNodes[i] is not a #text node. It will most
likely be a tableSection element - thead, tfoot or tbody - or maybe a
caption, col or colgroup.


That puzzled me too, but then I thought, the problem will be the same
with children, so hopefully the OP knows what he does.

To handle the issue of the text node, I would introduce some simple
checks like this:

if ( thisDoc
&& thisDoc.childNodes
&& thisDoc.childNodes[ i ]
&& thisDoc.childNodes[ i ].childNodes )
{
alert( thisDoc.childNodes[ i ].childNodes.length );
}


That seems rather a lot of work when it is likely that the OP is after
the table's rows collection, in which case Evertjan's reply fits the
bill: thisDoc.rows.length.

The above sequential test, if it was necessary, could be more efficient as:

var o;
if ( thisDoc
&& (o = thisDoc.childNodes)
&& (o = o[i])
&& (o = o.childNodes) )
{
alert(o.length);
}
:-)

--
Rob
Jun 19 '06 #6
I'm not sure this is what you need, but I use in my code something like:

thisDoc.childNodes[i].childNodes.length

and it works pretty well with Firefox, but I would verify if it has
children first with childNodes.hasChildren I think.

------
William
Angel wrote:
I have the following code

var thisDoc=document.getElementById("myTable"); // myTable is the name
of the table
alert(thisDoc.childNodes[i].children.length)

How do I change the second line of code for it to work in firefox?

Regards,
Angel

Jun 19 '06 #7
RobG wrote:
Laurent Bugnion wrote:
Hi,

RobG wrote:
Robert wrote:

Angel wrote:

> var thisDoc=document.getElementById("myTable"); // myTable is the name
> of the table
> alert(thisDoc.childNodes[i].children.length)
>
> How do I change the second line of code for it to work in firefox?

What about alert(thisDoc.childNodes[i].childNodes.length) ?
And I would expect it to work in IE6 too.

To handle the issue of the text node, I would introduce some simple
checks like this:

if ( thisDoc
&& thisDoc.childNodes
&& thisDoc.childNodes[ i ]
&& thisDoc.childNodes[ i ].childNodes )
{
alert( thisDoc.childNodes[ i ].childNodes.length );
}

That seems rather a lot of work when it is likely that the OP is after
the table's rows collection, in which case Evertjan's reply fits the
bill: thisDoc.rows.length.


I have to give a warning. IE6 can give a "Pure Virtual Call" error and
crash when mixing Core DOM methods and HTML Table DOM methods.
Jun 19 '06 #8
Robert wrote:
RobG wrote:
> Angel wrote:
>
>> var thisDoc=document.getElementById("myTable"); // myTable is the name
[...] That seems rather a lot of work when it is likely that the OP is after
the table's rows collection, in which case Evertjan's reply fits the
bill: thisDoc.rows.length.


I have to give a warning. IE6 can give a "Pure Virtual Call" error and
crash when mixing Core DOM methods and HTML Table DOM methods.


I'd expect that if that's true then it would have been mentioned
here before, do you have an example? As far as I can determine, it
hasn't. Microsoft themselves recommend using the DOM HTML Table
interface for manipulating tables:

<URL; http://msdn.microsoft.com/workshop/author/tables/buildtables.asp>
Note: their documentation for insertRow has so many errors I wouldn't
be surprised if they've got it completely backwards: :-(

<URL:
http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/insertrow.asp>

--
Rob

Jun 20 '06 #9
RobG wrote:
Robert wrote:
I have to give a warning. IE6 can give a "Pure Virtual Call" error and
crash when mixing Core DOM methods and HTML Table DOM methods.

I'd expect that if that's true then it would have been mentioned
here before, do you have an example? As far as I can determine, it
hasn't. Microsoft themselves recommend using the DOM HTML Table
interface for manipulating tables:

<URL; http://msdn.microsoft.com/workshop/author/tables/buildtables.asp>


I was confronted by this problem and saw IE6 crash consistently (tried
many computers) for no apparent reason. After debugging I traced the
problem to a DOM call. There was no reason for it to crash. I googled
and someone mentioned that this could happen when mixing those different
DOM methods. I had nothing to loose so I replaced the HTML Table DOM
Methods with Core DOM methods. I remember especially that I changed
using the rows and cells collection, so then doing it the hard way by
stepping through the childNodes. After this change the problems were gone.

If I find this google reference or the code I changed in CVS maybe I can
tell more.
Jun 20 '06 #10
Robert wrote:
RobG wrote:
Robert wrote:
I have to give a warning. IE6 can give a "Pure Virtual Call" error and
crash when mixing Core DOM methods and HTML Table DOM methods.


I'd expect that if that's true then it would have been mentioned
here before, do you have an example? As far as I can determine, it
hasn't. Microsoft themselves recommend using the DOM HTML Table
interface for manipulating tables:

<URL; http://msdn.microsoft.com/workshop/author/tables/buildtables.asp>


If I find this google reference or the code I changed in CVS maybe I can
tell more.


I think this is the thread that I found which made me change my javascript.
http://groups.google.com/group/micro...8675fc965b0500

"I was mixing DOM calls with table object model enumerations. Using only
DOM fixed it."
Jun 20 '06 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Good Enchiladas | last post by:
While building on a class library for an object model, I get the above error message. The steps to recreate the problem are as follows: 1. Build a RootLevel.dll containing only this code: ...
4
by: Robin Tucker | last post by:
Hi, I'm currently implementing a database with a tree structure in a table. The nodes in the tree are stored as records with a column called "Parent". The root of the tree has a "NULL" parent....
13
by: Julia Peterwitz | last post by:
I have a function that works with explorer but not with netscape. The problem is the function at line 5. 1 fSetSelectedDay(myElement){ 2 /* 3 ... 4 */ 5 var elementText =...
24
by: Charles Crume | last post by:
Hello; My "index.htm" page has 3 frames (content, navigation bar, and logo). I set the "SRC" of the "logo" frame to a blank gif image and then want to change it's contents after the other two...
1
by: Todd Cary | last post by:
In my previous post, I stated that some JavaScript I inherited does not work in Firefox but does work in IE 6 . I have now isolated a line where it fails in Firefox; the line with the property of...
7
by: GfxGuy | last post by:
I've seen this problem posted a million times, but I've read through all of them and can't figure out what I'm doing wrong. Simple example (this is the whole file, no editing): ---------- ...
19
by: Christian Fowler | last post by:
I have a VERY LARGE pile of geographic data that I am importing into a database (db of choice is postgres, though may hop to oracle if necessary). The data is strictly hierarchical - each node has...
8
by: Don Wash | last post by:
Hi There! I'm using VB.NET to create a TreeView application and unfortunately I could not find "Key" property in Node items of the TreeView. We used to have "Key" property in TreeView node...
0
by: Tim Mostad | last post by:
I have an app where I have implemented a drag and drop interface. I pass an object via a DoDragDrop method. The control that receives the drop gets the right data but when I break and try to look...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.