473,653 Members | 3,015 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.getEle mentById is returning an HTMLDivElement,
in IE 7, it is returning an Object.

For example:

<div id="errorTableD iv">
</div>

....

errorTableDiv = document.getEle mentById("error TableDiv");
alert(errorTabl eDiv);
errorTableDiv.a ppendChild(some TableNode);

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 6757
On Mar 27, 5:48 am, timet...@gmail. com wrote:
Relatively new to Javascript, please be gentle...

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

For example:

<div id="errorTableD iv">
</div>

...

errorTableDiv = document.getEle mentById("error TableDiv");
alert(errorTabl eDiv);
errorTableDiv.a ppendChild(some TableNode);

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(errorTabl eDiv.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.getEle mentById is returning an HTMLDivElement,
in IE 7, it is returning an Object.
For example:
<div id="errorTableD iv">
</div>
...
errorTableDiv = document.getEle mentById("error TableDiv");
alert(errorTabl eDiv);
errorTableDiv.a ppendChild(some TableNode);
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(errorTabl eDiv.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
22219
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 mine. I am using IE 6.0.28 (sp5) on a Windows 2000 Server. I am very new to DOM so I'm not ruling out that I'm doing something wrong. However, I am posting the code that I got from another site because I did notice that the examples were using...
10
2675
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 function with either MS IE 6.0 or Mozilla Firefox 0.9. Comments below indicate that if I hardcode an element ID I can avoid the error, but I obviously want to parameterize it. Here are some snippets of my code: -----snippet...
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
2435
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: <div class="small" style="display: none" id="menu1_menu"> when the heading is clicked: <a href=.. onClick="expandDiv('menu1')">
3
9257
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 work on FireFox or Netscape. What could be wrong? The function: function setActiveTab(tabNo) {
4
2250
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: document.getElementById(list_name_id).innerHTML=xmlHttp.responseText ; until now everything is OK the list is builds correctly. but when I use the document.getElementById(call_list_id).options.value I got an error saing "value is null or it is not an object" It seems that object list ID is null. Although...
29
19229
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 site and so far doing this has saved about 8KB of javascript (lots of ajax/dynamic elements). I just
3
2055
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 this javascript. The function is a "show/hide" for a form. I want to ensure that any possible previously entered value is cleared so the user starts with an empty field with focus. I have tried to ways, with naming and getElementById but in...
1
2227
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 script to update the display to the user depending on what they choose (qty, options, shipping etc.) I'm sure it's simple but I could really use a hand. Thanks!!
0
8370
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8283
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8470
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8590
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7302
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5620
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4147
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
1914
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1591
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.