From: Angel on
I have an application with heavy usage of DOM

Initially the application was supposed to be only IE specific, but now
we need to support it for Firefox also.

As an example consider the following HTML

<html>
<head></head>
<body>
<table border="1" cellspacing="5" cellpadding="5" id="RCTable">
<tr>
<td>R1, C1</td>
<td>R1, C2</td>
<td>R1, C3</td>
</tr>
<tr>
<td>R2, C1</td>
<td>R2, C2</td>
<td id="r2c3">R2, C3</td>
</tr>
</table>

<script language="JavaScript">
TableObject =
(document.getElementById('RCTable').getElementsByTagName('tr'));
alert(TableObject[1].childNodes[1].innerHTML);
</script>
</body>
</html>

In Firefox the alert displays "R2, C1"

However in IE the same alert displays "R2, C2"

How do I get both the browsers to read the same cells.?
How do i read the table contents in Firefox?
Does firefox support the innerText property?

Hope I make sense

Regards,
Angel

From: Martin Honnen on


Angel wrote:


> TableObject =
> (document.getElementById('RCTable').getElementsByTagName('tr'));
> alert(TableObject[1].childNodes[1].innerHTML);

> In Firefox the alert displays "R2, C1"
>
> However in IE the same alert displays "R2, C2"


There is a rows collection for table element objects and there is a
cells collection for table row (tr) elements which would allow you the
same access in Mozilla and Firefox and Opera.

Indexing childNodes to find an element node at a certain position does
not work cross browser without doing nodeType checks as the DOM tree
looks different, Mozilla includes white space text nodes in the DOM, IE
does not do that at all, Opera does it slightly different than Mozilla I
think.
--

Martin Honnen
http://JavaScript.FAQTs.com/
From: Robin Rattay on
Angel wrote:
> TableObject =
> (document.getElementById('RCTable').getElementsByTagName('tr'));
> alert(TableObject[1].childNodes[1].innerHTML);
>
> In Firefox the alert displays "R2, C1"

Yup, that's the content, of the second child node. The first child node
is the textnode before the table cell containing of the four spaces you
used to indent the code.

> However in IE the same alert displays "R2, C2"

As usally wrong.

> How do I get both the browsers to read the same cells.?

By using the rows und cells properties:

TableObject = document.getElementById('RCTable');
alert(TableObject.rows[1].cells[1].innerHTML);

> Does firefox support the innerText property?

Nope. You are probably looking for:
alert(TableObject.rows[1].cells[1].firstChild.data);

(This is the quick-hack version, to do it properly you need to get the
"data" of all children and append it.)

Robin
From: BootNic on
> "Angel" <jagushtes(a)gmail.com> wrote:
> news:1141992859.241438.60430(a)i39g2000cwa.googlegroups.com....
>
[snip]
> Does firefox support the innerText property?

It supports textContent.

<script language="JavaScript">
TableObject=document.getElementById('RCTable');
var x=TableObject.rows[1].cells[1];
alert(tx=(x.innerText)?x.innerText:x.textContent);
</script>

--
BootNic Friday, March 10, 2006 2:44 PM

A conclusion is the place where you get tired of thinking.
*Arthur Bloch*


From: BootNic on


> "BootNic" <Bootnic(a)bounce.prodigy.net> wrote:
> news:QGkQf.19526$NS6.8465(a)newssvr30.news.prodigy.com....
>
>> "Angel" <jagushtes(a)gmail.com> wrote:
>> news:1141992859.241438.60430(a)i39g2000cwa.googlegroups.com....
>>
> [snip]
>> Does firefox support the innerText property?
>
> It supports textContent.
>
> <script language="JavaScript">
> TableObject=document.getElementById('RCTable');
> var x=TableObject.rows[1].cells[1];
> alert(tx=(x.innerText)?x.innerText:x.textContent);
> </script>

I should have replaced language="JavaScript" with
type="text/javascript"


--
BootNic Friday, March 10, 2006 2:48 PM

"This is all very interesting, and I daresay you already see me
frothing at the mouth in a fit; but no, I am not; I am just winking
happy thoughts into a little tiddle cup."
*Nabokov, Lolita*