473,396 Members | 1,671 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

DOM for IE and Firefox

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').getElementsByT agName('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

Mar 10 '06 #1
6 4957


Angel wrote:

TableObject =
(document.getElementById('RCTable').getElementsByT agName('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/
Mar 10 '06 #2
Angel wrote:
TableObject =
(document.getElementById('RCTable').getElementsByT agName('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
Mar 10 '06 #3
> "Angel" <ja*******@gmail.com> wrote:
news:11*********************@i39g2000cwa.googlegro ups.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*
Mar 10 '06 #4

"BootNic" <Bo*****@bounce.prodigy.net> wrote:
news:QG******************@newssvr30.news.prodigy.c om....
"Angel" <ja*******@gmail.com> wrote:
news:11*********************@i39g2000cwa.googlegro ups.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*

Mar 10 '06 #5
Thanks a ton for all the help

I have a question more. How do I find the row number of a specific
element in a table

The following HTML sample works perfect in IE. On click of the
checkboxes, I am displaying the row number and its column number. How
do I manage the same in Firefox

<html>
<head>
<script language="javascript">
function selectedRow(object,cNumber)
{
while (object.tagName != 'TR')
{
object = object.parentNode;
}
RowNumber = object.rowIndex;
cellNumber = cNumber;
alert(RowNumber + " : " + cellNumber)
}

</script>
</head>

<body>
<table width="20%" border="1" cellpadding="0" cellspacing="0"
bordercolor="#CCCCCC" id=myTable name=myTable>
<tr id="1">
<td width="28%"><input name="r1c1" type="checkbox" id="r1c1"
onClick="selectedRow(this.parentElement,this.paren tNode.cellIndex)">
R1, C1</td>
<td width="32%"><input name="r1c2" type="checkbox" id="r1c2"
onClick="selectedRow(this.parentElement,this.paren tNode.cellIndex)">
R1, C2</td>
</tr>
<tr id="1">
<td><input name="r2c1" type="checkbox" id="r2c1"
onClick="selectedRow(this.parentElement,this.paren tNode.cellIndex)">
R2, C1</td>
<td><input name="r2c1" type="checkbox" id="r2c1"
onClick="selectedRow(this.parentElement,this.paren tNode.cellIndex)">
R2, C1</td>
</tr>
</table>
</body>
</html>

Mar 11 '06 #6


Angel wrote:

onClick="selectedRow(this.parentElement,this.paren tNode.cellIndex)">


Use parentNode only, not parentElement and Mozilla and other browsers
will do as parentNode is defined in the W3C DOM while parentElement is a
left over from IE 4 times.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Mar 11 '06 #7

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

Similar topics

3
by: Jeremy Epstein | last post by:
I've got a 4-page form that lets users enter a whole lot of information, which is then submitted and emailed at the end. All the fields are stored as session data. The whole thing works fine: ...
6
by: Geoff | last post by:
When trying to focus a field in Firefox, I get the following error: Error: " nsresult: "0x8057001e (NS_ERROR_XPC_JS_THREW_STRING)" location: "JS frame ::...
87
by: expertware | last post by:
Dear friends, My name is Pamela, I know little about CSS, but I would like to ask a question I have an image on a web page within a css layer: <DIV ID=MyLayer STYLE = "position:...
14
by: expertware | last post by:
Ok! to avoid confusion I will start a new argument. Thanks!! FIREFOX 1.0.7 AND IE6 viewed through DATATIME: a summary REPORT ===============================================================...
5
by: SPE - Stani's Python Editor | last post by:
Hi, During optimizing SPE for Ubuntu, I found something strange. I have Ubuntu 5.10 "The Breezy Badger" and unfortunately this code is not working: >>> import webbrowser >>>...
7
by: Coder | last post by:
Hi I have the following code in java script, it is not giving proper output in FIREFOX but running fine in IE... can anybody help me out to make this run in FIREFOX . <script...
12
by: amit | last post by:
Hello group, I'm kinda skeptical about a code is being used in my js program. All it does is checking what browser is being run and finds out if FLASH is installed or not. This code works...
6
by: scotty | last post by:
I have a script that loops through an existing table list and prepares each href element node to trigger a function when an image is clicked. The function that will be run passes a property value...
7
by: Carlos Mendonça | last post by:
Has anyone managed to get ClickOnce to work with Firefox? It seems to me that it still has the same issues VS 2K5 had. I appreciate any comments or tips.
3
by: SAL | last post by:
Hello, I did google this issue and found some stuff related to BrowserCaps section of either web.config or machine.config but it didn't work. It seems that most pages in my webapp are okay but a...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.