469,950 Members | 1,914 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,950 developers. It's quick & easy.

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 6672
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Andrea | last post: by
4 posts views Thread by the other john | last post: by
3 posts views Thread by GarryJones | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.