473,405 Members | 2,141 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,405 software developers and data experts.

getElementbyId problem in Firefox

TR
My document had the following nested DIV structure, with a possible
<SPAN> between the DIV and the <A> elements:

<div id="container">
<div id="D1">
<span>blah blah</span><br>
<A id="A1">item</a><br>
Jul 23 '05 #1
4 6807
DU
TR wrote:
My document had the following nested DIV structure, with a possible
<SPAN> between the DIV and the <A> elements:

<div id="container">
<div id="D1">
<span>blah blah</span><br>
<A id="A1">item</a><br>
.
.
.
<A id="A99" onmousedown='AOCP(1,99)'>item</a><br>
<div id="D2">
<A id="A76" onmousedown='AOCP(1,65)'>item</a><br>
.
.
.
<A id="A89" onmousedown='AOCP(1,34)'>item</a><br>
</div>
</div>

I see 3 div start tag and 2 div end tag.
When the user puts the mouse down on any ANCHOR, my script needs to
determine the anchor's parent DIV. The following script worked at first

85 function getParentDiv(elementid) {
86 /* elementid is the id of the <A> where the user is clicking;
the <a> may be nested inside a <SPAN> so loop until first DIV is
encountered; */
87
88 var activeElement = document.getElementById(elementid);
89 do
90 {
91 if (activeElement.tagName != 'DIV')
92 activeElement = activeElement.parentElement;
93 }
94 while ( (activeElement.tagName != 'DIV') || (activeElement.tagName
=='HTML') )
95
96 if ((activeElement != null) && (activeElement.tagName == 'DIV') )
97 return activeElement.id;
98 else
99 return -1;
100
101
102 } /* end function */
But the script stopped working with this error "Line 94 activeElement
has no properties" (taken from the Firefox javascript console) when I
merely added a second container DIV ("outercontainer"):
<div id="outercontainer">
<div id="container">
<div id="D1">
<span>blah blah</span><br>
<A id="A1">item</a><br>
.
.
.
<A id="A99" onmousedown='AOCP(1,99)'>item</a><br>
<div id="D2">
<A id="A76" onmousedown='AOCP(1,65)'>item</a><br>
.
.
.
<A id="A89" onmousedown='AOCP(1,34)'>item</a><br>
</div>
</div>
</div>

4 start tag, 3 end tag.
I don't understand why this error is occuring when my former structure
has merely been enclosed within a DIV. Could someone please explain?
After a certain depth of nesting, does getElementById stop working in
Firefox? The script continues to work fine in IE6 and Opera 7.

Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.6) Gecko/20040206
Firefox/0.8
Thanks
TR


1- Is your document perfectly valid? No improper nesting error reported
by the W3C HTML validator?
http://validator.w3.org/

2- Can you post an url? It is not only more convenient, making your post
smaller but it will show the http headers which is sometimes decisive
when trying to solve a problem

DU
Jul 23 '05 #2
TR wrote:
<snip>
88 var activeElement = document.getElementById(elementid);
89 do
90 {
91 if (activeElement.tagName != 'DIV')
92 activeElement = activeElement.parentElement; ^^^^^^^^^^^^^
parentElement - is a Microsoft proprietary property that has been
implemented in some other browsers but not in Mozilla/Gecko browsers.
The W3C Core DOM property with the most similar characteristics is -
parentNode -.

<snip I don't understand why this error is occuring when my former structure
has merely been enclosed within a DIV. Could someone please explain?
After a certain depth of nesting, does getElementById stop working in
Firefox? The script continues to work fine in IE6 and Opera 7.


As parentElement was always undefined in Firefox it is unlikely that
this code ever did what you thought it was doing in that browser.

Richard.
Jul 23 '05 #3
Thank you for the information. I was using devguru.com as my
online reference and would be grateful if you could suggest
another site that is comparable in approach but which identifies
the proprietary things. Do you know of a good one?
TR
P.S. Opera appears to support activeElement if Firefox does not.

Jul 23 '05 #4
Thanks for the reply. The missing closing tags were a feature of
my question, not of the HTML in the actual page. The HTML there is
valid. We're still working on the site and don't have it loaded
onto a webserver at the moment, or I'd be happy to provide a URL.
It looks as though the problem arose from my inadvertent use of a
Microsoft proprietary property.
TR
In article <c8**********@news.eusc.inter.net>,
dr*******@hotWIPETHISmail.com replies...

1- Is your document perfectly valid? No improper nesting error reported
by the W3C HTML validator?
http://validator.w3.org/

2- Can you post an url? It is not only more convenient, making your post
smaller but it will show the http headers which is sometimes decisive
when trying to solve a problem

DU

Jul 23 '05 #5

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

Similar topics

10
by: Dave Hammond | last post by:
Hi All, The following code works in IE but not Firefox. IE produces the expected "this is more text!" output, but Firefox produces "no more text". Any ideas why? <BODY> <FORM> <INPUT...
1
by: Muffinman | last post by:
Howdy, I've got here a sample of my function which is supposed to fade a certain piece of text to another colour. This line is then located in a for loop and it works pretty well in IE 6....
5
by: Derek Erb | last post by:
I am banging my head against the wall with this one. The following code snippets work perfectly fine in MSIE6. But produce an error in Firefox and do not work at all. BROWSER.HTM <HTML> .......
3
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...
5
by: Andrea | last post by:
I am trying to alter css using javascript as well as use the innerHTML function. I have pasted below 3 forms that access getElementById in slightly different ways (I wanted to rule out that it was...
4
by: the other john | last post by:
I came across a third party script I want to learn how to configure as well as learn more dhtml in the doing. I'm not much of a JS guy yet but I'm working on it. This script works fine in IE6...
13
by: RommelTJ | last post by:
Hi, My website (http://www.justiceinmexico.org/indextest.php) looks good in Firefox, but horrible in IE, and I think it's because of an error in the javascript of a free web ticker I got off the...
8
by: cyqotiq | last post by:
First, let me state that this is not necessarily a Firefox problem, as I haven't fully tested in IE just yet. Second, let me state that this is not the typical "getElementById not working Firefox"...
3
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
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
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: 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
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
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
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...
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
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,...
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...

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.