473,503 Members | 2,029 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

getElementById return value differences in Firefox/IE

Relatively new to Javascript, please be gentle...

In Firefox 2, document.getElementById is returning an HTMLDivElement,
in IE 7, it is returning an Object.

For example:

<div id="errorTableDiv">
</div>

....

errorTableDiv = document.getElementById("errorTableDiv");
alert(errorTableDiv);
errorTableDiv.appendChild(someTableNode);

Firefox prints HTMLDivElement and lets me appendChild() later on
IE prints Object and gives an error on the appendChild()

I do not understand why this happens or what the most socially
acceptable way to fix it is.

Mar 26 '07 #1
3 6746
On Mar 27, 5:48 am, timet...@gmail.com wrote:
Relatively new to Javascript, please be gentle...

In Firefox 2, document.getElementById is returning an HTMLDivElement,
in IE 7, it is returning an Object.

For example:

<div id="errorTableDiv">
</div>

...

errorTableDiv = document.getElementById("errorTableDiv");
alert(errorTableDiv);
errorTableDiv.appendChild(someTableNode);

Firefox prints HTMLDivElement and lets me appendChild() later on
IE prints Object and gives an error on the appendChild()
That IE and Firefox report differently isn't a problem, that's just a
difference in the browsers. Use:

alert(errorTableDiv.tagName);

to see what you've got. To understand the appendChild issue, you're
going to have to post a minimal example that demonstrates the issue.
--
Rob

Mar 26 '07 #2
Thanks, this pointed me in the right direction. I looked up the
appendChild rules and I was appending to the table node instead of the
tbody itself.

It's working now.

On Mar 26, 2:20 pm, "RobG" <r...@iinet.net.auwrote:
On Mar 27, 5:48 am, timet...@gmail.com wrote:
Relatively new to Javascript, please be gentle...
In Firefox 2, document.getElementById is returning an HTMLDivElement,
in IE 7, it is returning an Object.
For example:
<div id="errorTableDiv">
</div>
...
errorTableDiv = document.getElementById("errorTableDiv");
alert(errorTableDiv);
errorTableDiv.appendChild(someTableNode);
Firefox prints HTMLDivElement and lets me appendChild() later on
IE prints Object and gives an error on the appendChild()

That IE and Firefox report differently isn't a problem, that's just a
difference in the browsers. Use:

alert(errorTableDiv.tagName);

to see what you've got. To understand the appendChild issue, you're
going to have to post a minimal example that demonstrates the issue.

--
Rob

Mar 26 '07 #3
On Mar 27, 7:20 am, timet...@gmail.com wrote:
Thanks, this pointed me in the right direction. I looked up the
appendChild rules and I was appending to the table node instead of the
tbody itself.
Please don't top post here, reply below trimmed quotes.

I had in inkling you were using tables, but your example was a div so
let it slide. To put rows into tables, use the table's insertRow
method, then you don't care about tBody elements (which will be
inserted into tables by all browsers whether there are tbody tags in
the HTML or not):

<URL: http://developer.mozilla.org/en/docs...able_Interface
>
You can also use the insertRow method with a tBody (or other
tableSection element) if you wish.
--
Rob
Mar 27 '07 #4

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

Similar topics

2
22212
by: Chris | last post by:
Hi, I'm having a problem utilizing the DOM. I tried using my own code, but it wasn't working, so I tried to use code straight from another web site and it verified that the problem may not be...
10
2649
by: JJA | last post by:
I'm trying to use document.getElementByID inside a function where the ID is passed as an argument. I get the same error ("Element has no properties") on the same statement inside the commonCheck...
5
440
by: Christian Ista | last post by:
Hello, I have this javascript function Function MyFunction(v,id){ document.getElementById(id).value = v } No problem with IE but not work with Firefox.
3
2418
by: InvisibleMan | last post by:
Thanks in Advance for any help on this - its truely sending my head in loops... so I appreciate your efforts! okay, I have a javascript listed below that drops down submenus contained within:...
3
9241
by: davidkarlsson74 | last post by:
Error: document.getElementById("folderMenu").cells has no properties File: http://www.volkswagen.se/tillbehor/js/foldermenu.js Rad: 49 The function activates different DIV:s, but doesn't seem to...
4
2238
by: raknin | last post by:
Hi, I am creating dynamic list in the server through php and insert it using ajax. for ajax I using the following statement: ...
29
19141
by: Nick | last post by:
I've seen a few frameworks use the following: function $(id) { return document.getElementById(id); } Then to use: $('something').innerHTML = 'blah'; I'm just trying to roll this out to my...
3
2047
by: GarryJones | last post by:
The following works in MSIE but not firefox. I suspect it has something to do with the fact that the element I am trying to access is not the "tid" which is the name of the DIV that is passed to...
1
2216
by: vikD | last post by:
Hello, I'm really bad at javascript but I managed to get the code below to work in IE but firefox gives this error... Error: document.getElementById.formall is undefined Basically use the...
0
7204
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
7091
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
7282
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
7464
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...
1
5018
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
4680
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
3171
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...
1
741
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
391
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.